qq_client.java
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:2k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package client;
- import java.net.*;import java.util.ArrayList;
- import java.util.Date;
- import java.io.*;
- import java.awt.event.*;import java.awt.*;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTextArea;
- public class qq_client
- {
- String name1;
- JFrame f;
- JPanel panelx=new JPanel();
- final JTextArea input=new JTextArea(3,20);
- //加final修饰是为了在内嵌类中访问
- JTextArea display=new JTextArea(5,20);
- JScrollPane js=new JScrollPane(display);
- JScrollPane js1=new JScrollPane(input);
- JPanel jp=new JPanel();
- JButton d=new JButton("发送:");
- public qq_client(String s,int b,String name) throws IOException {
- this.name1=name;
- f=new JFrame("client-"+name1);
- panelx.setLayout(new GridLayout(2,1,15,15));
- f=new JFrame("client-"+serverthread.name);
- panelx.add(js);
- panelx.add(js1);
- jp.add(d);
- System.out.println(s+" "+b);
- Socket s1 = new Socket(s,b);
- //连接服务器
- ObjectInputStream dis =new ObjectInputStream(s1.getInputStream());
- final ObjectOutputStream dos = new ObjectOutputStream(s1.getOutputStream());
- //panelx.add(input);
- // panelx.add(display);
- f.add(panelx,BorderLayout.CENTER);
- f.add(jp,BorderLayout.SOUTH);
- f.setSize(300,300);
- f.setVisible(true);
- new clientthread(dis,display);
- //创建一个接收数据线程
- d.addActionListener(new ActionListener(){
- //用匿名内嵌类处理
- public void actionPerformed(ActionEvent e) {
- try{
- ArrayList arr=new ArrayList();
- arr.add(input.getText());
- arr.add(name1);
- dos.writeObject(arr);
- display.append(new Date().toString()+name1+"n"+input.getText()+"n");
- //发送数据
- input.setText("");
- }
- catch(IOException z)
- {
- }
- }
- }
- );
- }
- }