package chat;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
public class TestCilent extends JFrame implements ActionListener {
DataInputStream dis;
DataOutputStream dos;
JTextField tf;
JTextArea ta;
String s11, s22;
public TestCilent(String s1, String s2) {
this.setTitle("�����ҵĿͻ���");
JScrollPane jp = new JScrollPane();
ta = new JTextArea(10, 10);
tf = new JTextField(20);
JPanel p=new JPanel();
JButton b = new JButton("����");
b.addActionListener(this);
tf.addActionListener(this);
p.add(tf);
p.add(b);
jp.setViewportView(ta);
this.getContentPane().add(jp);
this.getContentPane().add(jp);
this.setSize(350, 250);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.s11 = s1;
this.s22 = s2;
this.setVisible(true);
tf.requestFocus();
this.connect();
this.createReadThread();
}
public void connect() {
try {
Socket s2 = new Socket(s22, 911);
InputStream is = s2.getInputStream();
dis = new DataInputStream(is);
OutputStream os = s2.getOutputStream();
dos = new DataOutputStream(os);
} catch (IOException e2) {
System.out.println("l�ӷ�������ϣ�");
}
}
public void createReadThread() {
ReadThread rt = new ReadThread(this.ta, this.dis);
rt.start();
}
public void actionPerformed(ActionEvent e) {
try {
String s = tf.getText();
dos.writeUTF(s11 + "˵��" + s);
ta.append("�Լ�˵��" + s);
ta.append("\n");
tf.setText("");
tf.requestFocus();
} catch (IOException e1)
{
e1.printStackTrace();
}
}
}
阅读(3116) | 评论(0) | 转发(0) |