FileDocCategorySizeDatePackage
AppletClient.javaAPI DocExample2683Thu Aug 08 12:34:18 BST 1996None

AppletClient

public class AppletClient extends Applet

Fields Summary
public static final int
PORT
Socket
s
DataInputStream
in
PrintStream
out
TextField
inputfield
TextArea
outputarea
StreamListener
listener
Constructors Summary
Methods Summary
public booleanaction(java.awt.Event e, java.lang.Object what)

        if (e.target == inputfield) {
            out.println((String)e.arg);
            inputfield.setText("");
            return true;
        }
        return false;
    
public voidinit()

    
    // Create a socket to communicate with a server on port 6789 of the
    // host that the applet's code is on.  Create streams to use with
    // the socket.  Then create a TextField for user input and a TextArea
    // for server output.  Finally, create a thread to wait for and 
    // display server output.
       
        try {
            s = new Socket(this.getCodeBase().getHost(), PORT);
            in = new DataInputStream(s.getInputStream());
            out = new PrintStream(s.getOutputStream());

            inputfield = new TextField();
            outputarea = new TextArea();
            outputarea.setEditable(false);
            this.setLayout(new BorderLayout());
            this.add("North", inputfield);
            this.add("Center", outputarea);
            
            listener = new StreamListener(in, outputarea);

            this.showStatus("Connected to " 
                    + s.getInetAddress().getHostName() 
                    + ":" + s.getPort());
        }
        catch (IOException e) { this.showStatus(e.toString()); }