import java.awt.*; import java.io.*; import java.net.*; public class ReadText extends java.applet.Applet implements Runnable { URL url; Thread runner; TextArea ta = new TextArea("Read Text..."); public void init() { try { url = new URL(getCodeBase(), "ReadText.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() { URLConnection conn = null; DataInputStream data = null; String line; StringBuffer buf = new StringBuffer(); try { conn = url.openConnection(); conn.connect(); ta.setText("Connection opened..."); data = new DataInputStream(new BufferedInputStream(conn.getInputStream())); 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 ReadText class