客户端:
package chatroom;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.io.*;
import javax.swing.*;
public class client extends JFrame implements ActionListener,Runnable{
JPanel conn,text,send;
JLabel name,sendto;
JComboBox list;
JButton con,snd,clear;
JTextArea talk;
JTextField who,say;
JScrollPane jsp;
Socket client;
InputStream is;
OutputStream os;
PrintStream ps;
BufferedReader br;
String receive,yousay;
Thread th;
DataInputStream dis;
Double tof;
client()
{
super("聊天室客户端");
this.setSize(800,600);
this.setResizable(false);
conn=new JPanel();
text=new JPanel();
send=new JPanel();
this.getContentPane().add(conn);
conn.setBounds(0, 0, this.getWidth(),50);
name=new JLabel("姓名:");
who=new JTextField();
con=new JButton("连接");
conn.setLayout(null);
conn.add(name);
name.setBounds(30, 10, 50, 25);
conn.add(who);
who.setBounds(80, 10, 150, 25);
conn.add(con);
con.setBounds(250,10, 60, 25);
this.getContentPane().add(text);
text.setBounds(0,50,this.getWidth(),450);
text.setLayout(new BorderLayout());
jsp=new JScrollPane();
talk=new JTextArea();
jsp.getViewport().setView(talk);
text.add(jsp,"Center");
talk.setLineWrap(true);
this.getContentPane().add(send);
send.setLayout(null);