home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-12-14 | 2.0 KB | 79 lines |
-
- import java.awt.*;
- import java.awt.event.*;
- import java.net.*;
- import java.io.*;
-
- public class GetInetFile extends Frame implements Runnable
- {
- Thread thread1;
- URL doc;
- TextArea body = new TextArea("Getting text...");
-
- public GetInetFile()
- {
- super("Get URL");
- add(body);
- try
- {
- doc = new URL("http://www.lads.com/ads/launch.html");
- }//try
- catch (MalformedURLException e)
- {
- System.out.println("Bad URL: " + doc);
- }//catch
-
- }//GetInetFile
-
-
- public static void main(String[] arguments)
- {
- GetInetFile frame1 = new GetInetFile();
-
- WindowListener l = new WindowAdapter()
- {
- public void windowClosing(WindowEvent e)
- {
- System.exit(0);
- }//windowClosing
- };//WindowListener
-
- frame1.addWindowListener(l);
- frame1.pack();
- frame1.setVisible(true);
- if (frame1.thread1 == null)
- {
- frame1.thread1 = new Thread(frame1);
- frame1.thread1.start();
- }//null
- }//main
-
- public void run()
- {
- URLConnection URLConn = null;
- InputStreamReader inStream;
- BufferedReader info;
- String line1;
- StringBuffer strBuffer = new StringBuffer();
- try
- {
- URLConn = this.doc.openConnection();
- URLConn.connect();
- body.setText("Connection opened ... ");
- inStream = new InputStreamReader(URLConn.getInputStream());
- info = new BufferedReader(inStream);
- body.setText("Reading data ...");
- while ((line1 = info.readLine()) != null)
- {
- strBuffer.append(line1 + "\n");
- }//while
- body.setText(strBuffer.toString());
- }//try
- catch (IOException e)
- {
- System.out.println("IO Error:" + e.getMessage());
- }//catch
- }//run
- }// class Getfile
-
-