import java.awt.*;
import java.net.*;
import java.io.*;

public class viewAction extends java.applet.Applet implements Runnable {
Thread t;
TextField tf = new TextField();
String str = null;
DataOutputStream out; 

  public void init(){
     setLayout(null);
     add(tf);    
     tf.reshape(5,5,100,25);
  }


  public boolean handleEvent(Event e){
     if(e.target instanceof TextField){
	try{
          if(e.key == 10 /*enterkey*/ && e.id==Event.KEY_PRESS){
           out.writeBytes(tf.getText()+"\n");
           out.flush();
           tf.setText("");
           return true;
          }
	}catch(Exception ex){}
     }
     return false;
  }

  public void start(){
     t = new Thread(this);
     t.start();
  }
  public void stop(){
    if(t!=null) t.stop();
    t=null;
  }

  public void paint(Graphics g){
       g.drawString(str,19,40);
  }


  public void run(){
    try{
       Socket s   = new Socket("artcontext.org", 4001);
       out = new DataOutputStream(s.getOutputStream());
       BufferedReader in
          = new BufferedReader(new InputStreamReader(s.getInputStream()));
       //DataInputStream in  = new DataInputStream(new BufferedInputStream(s.getInputStream()));
 
      while((str=in.readLine())!=null){
           System.out.println(str+"  len="+str.length());
		   repaint();
      }

      }catch(Exception e){

     } 
  }
}
