clientthread.java
资源名称:QQ.rar [点击查看]
上传用户:hongdaled
上传日期:2007-10-03
资源大小:680k
文件大小:1k
源码类别:
ICQ/即时通讯
开发平台:
Java
- package client;
- import java.awt.TextArea;
- import java.io.DataInputStream;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.HashMap;
- import javax.swing.JTextArea;
- class clientthread extends Thread {
- public ObjectInputStream dis;
- public JTextArea displayarea;
- public clientthread(ObjectInputStream dis , JTextArea m)
- {
- this.dis=dis;
- displayarea=m;
- this.start();
- }
- public void run()
- { try {
- while(true) {
- Object oo = dis.readObject();
- if(oo instanceof ArrayList)
- { //读取其他客户经服务器转发的消息
- ArrayList str=(ArrayList)oo;
- if(str.size()==2){
- displayarea.append(new Date().toString()+str.get(1).toString()+"说:"+"n"+str.get(0).toString()+"n");
- }
- }
- }
- }
- catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- }
- }
- //将消息添加到文本域显示
- }