import java.awt.*; import java.awt.event.*; import java.net.*; import java.io.*; public class GetFileApplication extends Frame implements Runnable { Thread runner; URL page; static String page_name; TextArea box = new TextArea("Getting the text ...."); public GetFileApplication() { super("Get File"); add(box); try { page= new URL(page_name); } catch (MalformedURLException e) { System.out.println("Bad URL: " + page_name); } } public static void main(String[] args) { page_name = new String(args[0]); System.out.println("Trying to open " + page_name); GetFileApplication frame = new GetFileApplication(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; frame.addWindowListener(l); //to handle window events frame.pack(); frame.setVisible(true); //make frame appear if(frame.runner == null) { //start thread running frame.runner = new Thread(frame); frame.runner.start(); } } //called automatically when create instance of this GetFile class //and subsequently call its inherited start() method. public void run() { URLConnection conn = null; InputStreamReader in; BufferedReader data; String line; StringBuffer buf = new StringBuffer(); try { conn = this.page.openConnection(); //create a URLConnection object wiht page URL conn.connect(); //connect box.setText("Connection opened...."); in = new InputStreamReader(conn.getInputStream()); //get inputstream tied to URLConnection data = new BufferedReader(in); box.setText("Reading data......"); while((line = data.readLine()) != null) //while data still in URL stream { buf.append(line + "\n"); } box.setText(buf.toString());//dump contents of buffer into box TextArea } catch (IOException e) { System.out.println("IO Error:" + e.getMessage()); } } }