Chinaunix首页 | 论坛 | 博客
  • 博客访问: 592825
  • 博文数量: 110
  • 博客积分: 8016
  • 博客等级: 中将
  • 技术积分: 1217
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-28 10:14
文章分类

全部博文(110)

文章存档

2008年(1)

2007年(13)

2006年(96)

我的朋友

分类: Java

2007-12-09 21:58:28

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();
  }
 }
}
阅读(3072) | 评论(0) | 转发(0) |
0

上一篇:一对一聊天程序(服务器)

下一篇:BPM

给主人留下些什么吧!~~