java聊天室源代码 第4页
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.net.*;
/*
* 服务端的侦听类
*/
www.751com.cn
UserLinkList userLinkList;//用户链表
Node client;
ServerReceive recvThread;
public boolean isStop;
/*
* 聊天服务端的用户上线于下线侦听类
*/
public ServerListen(ServerSocket server,JComboBox combobox,
JTextArea textarea,JTextField textfield,UserLinkList userLinkList){
this.server = server;
this.combobox = combobox;
this.textarea = textarea;
this.textfield = textfield;
this.userLinkList = userLinkList;
isStop = false;
}
public void run(){
while(!isStop && !server.isClosed()){
try{
client = new Node();
client.socket = server.accept();
client.output = new ObjectOutputStream(client.socket.getOutputStream());
client.output.flush();
client.input = new ObjectInputStream(client.socket.getInputStream());
client.username = (String)client.input.readObject();
//显示提示信息
combobox.addItem(client.username);
userLinkList.addUser(client);
textarea.append("用户 " + client.username + " 上线" + "\n");
textfield.setText("在线用户" + userLinkList.getCount() + "人\n");
recvThread = new ServerReceive(textarea,textfield,
combobox,client,userLinkList);
recvThread.start();
}
catch(Exception e){
}
}
}
}"
上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >>