import java.applet.Applet; import java.net.*; import java.awt.*; import java.io.*; public class chargenApplet extends Applet implements URLStreamHandlerFactory, Runnable { TextArea theText; URL theServer; DataInputStream dis = null; public static void main(String[] args) { Frame f = new Frame("chargen applet"); f.resize(300, 300); f.move(50, 50); chargenApplet cg = new chargenApplet(); f.add("Center", cg); cg.init(); f.show(); cg.start(); } public void init() { URL.setURLStreamHandlerFactory(this); setLayout(new BorderLayout()); theText = new TextArea(); add("Center", theText); String s = "chargen://sunsite.unc.edu/"; try { theServer = new URL(s); dis = new DataInputStream(theServer.openStream()); } catch (MalformedURLException e) { theText.setText("Error: Could not handle URL " + s); } catch (IOException e) { theText.setText("Error: Could not open connection to " + s); theText.appendText("There may not be a chargen server running" + "on this host or network connections may be disallowed."); } Thread t = new Thread(this); t.start(); } public URLStreamHandler createURLStreamHandler(String protocol) { if (protocol.equalsIgnoreCase("chargen")) { return new chargenURLStreamHandler(); } else { return null; } } public void run() { try { String theLine; if (dis != null) { while ((theLine = dis.readLine()) != null) { theText.appendText(theLine + "\r"); } } } catch (IOException e) { } } }