QQClient.java
//axun @copy right
package axun.com;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class QQClient {
private JFrame f=new JFrame("QQ客户端");
private TextArea t1=new TextArea();
private TextArea t2=new TextArea();
private Button b=new Button("发送");
//一下是 网络通信用的变量
DataOutputStream dos=null;
BufferedReader br=null;
DataInputStream dis=null;
public void Addt1(String s){
t1.append(s);
}
public QQClient(){
f.setSize(400,300);
f.setLayout(new GridLayout(3,1));
t1.setEditable(false);  //不可编辑
f.add(t1);
f.add(t2);
f.add(b);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
b.addActionListener(new bListener());
}
public static void main(String[] args) throws Exception {
QQClient client=new QQClient();
InputStream in=null;
OutputStream out=null;
String string=null;
Socket s=new Socket("localhost",4545);
out=s.getOutputStream();
in=s.getInputStream();
client.dis=new DataInputStream(in);
client.dos=new DataOutputStream(out);
Listen2 l=new Listen2(client,client.dis);
Thread t=new Thread(l);
t.start();
}
class bListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
try{
dos.writeUTF(t2.getText());
Addt1("发送:"+"/n");
Addt1("    "+t2.getText()+"/n");
t2.setText("");
}catch(Exception ep){
}
}
}
}
class Listen2 implements Runnable{
private QQClient client=null;
private DataInputStream dis=null;
private String s=null;
Listen2(QQClient client,DataInputStream dis){
this.client=client;
this.dis=dis;
}
public void run() {
// TODO Auto-generated method stub
try{
while(true){
s=dis.readUTF();
client.Addt1("收到:"+"/n");
client.Addt1("    "+s+"/n");
}
}catch(Exception e){
}
}
}