import java.awt.*;	import java.awt.event.*;

import java.net.*;	import java.io.*;
import java.util.Hashtable;
import java.util.Enumeration;
import java.util.StringTokenizer;

		// the gui definitions, without event handling
class PeerListFrame extends Frame{
	
	public List peerlist;
	public Button refresh, exit;
	public TextField mywords;
	
	
	public PeerListFrame(String welcomemsg) {
		
		super(welcomemsg);
		Panel but = new Panel();
		but.add(refresh = new Button("Refresh"));
		but.add(exit = new Button("Exit"));
		
		super.add(but, BorderLayout.NORTH);
		super.add(peerlist = new List(10), BorderLayout.CENTER);
		super.add(mywords = new TextField(30),BorderLayout.SOUTH);
		super.setSize(200,300);
	}
}

class PeerWindow extends Frame {
	
	public TextArea text;
	
	public PeerWindow(String peername) {
		
		super(peername);
		super.add(text = new TextArea(8,20));
		text.setEditable(false);
		super.setSize(200,100);
	}
	public void finalize() {
		try {
			text = null;
			super.finalize();
		}catch (Throwable th){}
	}
}
		//refinement of InputStream and OutputStream obtained from Socket instances
class Commlinks {
	public PrintStream out;
	public BufferedReader in;
	Socket so;
	
	
	public Commlinks(Socket soc) throws Exception {
		so = soc;
		out = new PrintStream(so.getOutputStream());
		in = new BufferedReader(new InputStreamReader(so.getInputStream()));
	}
}

class Commands {
	
	public static final String TO = "/to ";		//Note the space. do not remove
	public static final String LIST = "/list";
	public static final String BYE = "/bye";
	public static final String NICK = "/nick";	
}

class Msg_Parser {
	
	public static String[] makeArray(String msg) {
		
		StringTokenizer st = new StringTokenizer(msg);
		int tokencount = st.countTokens();
		String [] ret = new String [tokencount];
		for (int i = 0; i < tokencount; i ++ )
			ret[i] = st.nextToken();	
		return ret;
		
	}
	
/* Message format
 *`````````````````````
 * client sends message using
 * /to <peernick> <message> <cr>
 * client sends command to server using
 * /command <param1> <param2> ...
 * The commands supported here are list, nick, bye
 * 		list has no args
 * 		nick <mynickname>
 * 		bye has no args
 *
 * server forwards message to client as
 * <peername>: <message> <cr>		This is directly displayable by client 
 * the list response from server is
 * list <peer1> <peer2> <peer3> ...
 */		
}