import java.awt.*; import java.io.*; import java.net.*; public class ReadStream extends java.applet.Applet implements Runnable { URL url; Thread runner; TextArea ta = new TextArea("Read Stream..."); public void init() { try { url = new URL(getCodeBase(), "ReadStream.java"); } catch ( MalformedURLException e) { System.out.println("Bad URL: " + url); } setLayout(new BorderLayout()); ta.setFont(new Font("TimesRoman", Font.BOLD, 18)); add("Center", ta); } public void start() { if (runner == null) { runner = new Thread(this); runner.start(); } } public void stop() { if (runner != null) { runner.stop(); runner = null; } } public void run() { DataInputStream data = null; String line; StringBuffer buf = new StringBuffer(); try { ta.setText("Open Stream..."); data = new DataInputStream(new BufferedInputStream( url.openStream())); ta.setText("Reading data..."); while ((line = data.readLine()) != null) buf.append(line + "\n"); ta.setText(buf.toString()); } catch (IOException e) { System.out.println("IO Error:" + e.getMessage()); } } } // end ReadStream class