[5015] in java-interest

home help back first fref pref prev next nref lref last post

problems hooking up a TextArea to a DataInputStream

daemon@ATHENA.MIT.EDU (James Waldrop)
Thu Jan 25 23:22:07 1996

To: java-interest@java.Eng.Sun.COM
Date: Thu, 25 Jan 1996 18:31:44 -0800
From: James Waldrop <sulam@construct.net>


Hi folks, thanks for any help you can give me on the following problem.

Imagine that I'm trying to write a simple line-mode telnet applet. 
For the input window, I want to have a TextField, and for the output
window I want to have a TextArea.

I've gotten a socket hooked up to a DataInputStream, and am even able
to call readLine() on it and get back something.  The problem is that
this isn't working past the first line.  I suspect the problem is
something in the way I'm handling the threads, since I'm not clear
on how it should be done.  Anyway, the relevant bits of code are:

If anyone has something like this that uses the Beta API and is an
applet, I'd appreciate pointers to sample code.

public class LineMode extends Applet implements Runnable {
    private Socket socket;
    private DataInputStream in;
    private TextArea outputArea;
    private Thread engine = null;

    public void init() {
	Panel blah = new Panel();
	setLayout(new BorderLayout());
	add("Center", blah);
	outputArea = new TextArea(24,80);
	blah.add(outputArea);

	// I've deleted all the exception stuff for brevity.

	socket = new Socket("xxx", 7777); // or whatever
	in = new DataInputStream(socket.getInputStream());
    }

    public void start() {  //  This is where I'm screwing up I suspect.
	if (engine == null) {
	    engine = new Thread(this);
	    engine.start();
	}
    }

    public void run() {
	String line;

	try { line = in.readLine(); }
	catch (Exception e) { line = null; }

	if (line != null) { outputArea.appendText(line); }
}

// EOF
--
James Waldrop                        /          Technical Director
sulam@construct.net              /              Construct Internet Design
sulam@well.com               /                  http://www.construct.net
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post