//******************************************************************************
// read.java:	Applet
//
//******************************************************************************
import java.applet.*;
import java.awt.*;
import java.net.*;
import java.io.*;
import java.io.*;

//==============================================================================
// Main Class for applet read
//
//==============================================================================
public class read extends Applet
{
	String m_file = "http://www.csclub.uwaterloo.ca/~yhchan/lsc93.txt";
	final String PARAM_file = "file";
	TextArea textarea;

	public void init()
	{
		String param;
		String data;
		byte buf[] = new byte[500000];

		param = getParameter(PARAM_file);
		if (param != null)
			m_file = param;

    	resize(640, 400);

		textarea = new TextArea(24,80);
		this.add(textarea);

		try
		{
             URL url = new URL(m_file);
             URLConnection urlConnection = url.openConnection();
             urlConnection.connect();

             // if the file does not exist, the following will throw an exception:
             InputStream is = urlConnection.getInputStream();

             int r = is.read(buf);
		}
		catch (Exception ex)
		{
			 textarea.appendText("File open Error!");
             System.exit(1);
		}

		
		data = new String(buf,0);
		textarea.appendText(data);
	}
	

	public String getAppletInfo()
	{
		return "Name: read\r\n" +
		       "Author: Horace Chan\r\n" +
		       "Created with Microsoft Visual J++ Version 1.0";
	}

	public String[][] getParameterInfo()
	{
		String[][] info =
		{
			{ PARAM_file, "String", "Parameter description" },
		};
		return info;		
	}
}
