/* Copyright Andy C. Deck 1999 All rights reserved. */    
import java.io.*;
import java.net.*;
import java.awt.*;

public class users extends Frame implements Runnable{
Thread thread;
List list;

    public users() {
     super("Users");
     setLayout(new BorderLayout());
     list = new List();
     add("Center",list);
     add("South",new Button("Okay"));
     start();
     pack();
     show();
   }

   public boolean handleEvent(Event e){
        if(e.id == Event.WINDOW_DESTROY){
                hide(); // button down
		stop();
        }
	if(e.target instanceof Button){
		if(e.id == Event.ACTION_EVENT){
			hide();
			stop();
		}
	}
        return true;
   }                     

    public void start(){
	thread = new Thread(this);
        thread.start();
    }

    public void stop(){
	if(thread!=null) thread.stop();
	thread = null;
    }

    public void run(){
	String get = "GET /draw/cgi/users.cgi HTTP/1.0\n\n";
	byte[] GET = new byte[34];
  	String line         = null;
	Socket sock         = null;
  	DataInputStream is  = null;
	get.getBytes(0,34,GET,0);
	try{
		sock = new Socket("artcontext.com", 80); 
	        sock.getOutputStream().write(GET);
		is = new DataInputStream(new BufferedInputStream(sock.getInputStream()));
		while((line= is.readLine()).length()>1) ;
		while((line= is.readLine()) != null)
			list.addItem(line);		
        }
        catch(InterruptedException ie){
        }
        catch(EOFException io){
        }
        catch(IOException ex){
        }
       thread=null;
        try{
		  if(sock!=null) sock.close();
		  sock=null;
		}catch(IOException e){}
        }
}
