FileDocCategorySizeDatePackage
chargenApplet.javaAPI DocExample1676Thu Apr 03 15:27:02 BST 1997None

chargenApplet

public class chargenApplet extends Applet implements Runnable, URLStreamHandlerFactory

Fields Summary
TextArea
theText
URL
theServer
DataInputStream
dis
Constructors Summary
Methods Summary
public java.net.URLStreamHandlercreateURLStreamHandler(java.lang.String protocol)

  
    if (protocol.equalsIgnoreCase("chargen")) {
      return new chargenURLStreamHandler();
    }
    else {
      return null;
    }
    
  
public voidinit()

  
    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 static voidmain(java.lang.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 voidrun()

  
    try {
      String theLine;
      if (dis != null) {
        while ((theLine = dis.readLine()) != null) {
          theText.appendText(theLine + "\r");
        }
      }
    }
    catch (IOException e) {
    }