资源简介
java实现的聊天系统,有操作界面,易操作

代码片段和文件信息
//客户端程序
package chat;
import java.io.*;
import java.net.*;
import javax.swing.*;
import protocols.ChatRequest;
import protocols.ConnectionNotice;
import protocols.KickedOutNotice;
import protocols.LogOut;
import protocols.Message;
import protocols.ServerShutDown;
import protocols.UpdateList;
//此类用来处理和服务器的连接
public class ChatClient {
private boolean connected;//是否连接标志
int serverSocketNumber;//连接数目
String serverAddress;//服务器地址
private Socket socket;//端口号
String Name;//机器名
private int clientID;
objectOutputStream out;//输出流
objectInputStream in;//输入流
DefaultListModel clientList;
private InputListener listener;//监听端口
ClientInterface window;
//对进来的信息进行回应
class InputListener extends Thread {
//提供中断循环的方式
boolean running = false;
//实现线程类的run()方法处理发送过来的操作消息如聊天请求,用户列表更新等
public void run() {
//一直循环直到Listener停止
while( true ){
if( running ){
//测试信息类型并作出相应的反映
try {
object serverMsg = in.readobject();
if( serverMsg instanceof Message ){
window.showMessage((Message)serverMsg);
}
else if( serverMsg instanceof ChatRequest){
window.openNewTab(((ChatRequest)serverMsg).senderId );
}
else if( serverMsg instanceof UpdateList ){
//如果有新的成员加入
if(((UpdateList)serverMsg).requestType == true){
clientList.addElement( ((UpdateList)serverMsg).newClient );
}
//当有成员退出
else {
window.notifyUserLeft( ((UpdateList)serverMsg).newClient );
clientList.removeElement(((UpdateList)serverMsg).newClient);
}
}
else if(serverMsg instanceof ServerShutDown) {
disconnectFromServer( false );//从服务器断开连接
window.notifyDisconnect();
JOptionPane.showMessageDialog( window
“Server Has Been Shut Down““Connection Error“JOptionPane.ERROR_MESSAGE );
}
else if(serverMsg instanceof KickedOutNotice){
disconnectFromServer( false );//从服务器断开连接
window.notifyDisconnect();//关闭窗口
JOptionPane.showMessageDialog( window
“Server Kicked You Out““Connection Error“JOptionPane.ERROR_MESSAGE );
}
}
catch(ClassNotFoundException cnfe){
JOptionPane.showMessageDialog( window
“Class of a serialized object cannot be found.“
“Termination Error“ JOptionPane.ERROR_MESSAGE );
shutDown();//退出程序
}
catch( InvalidClassException ice ){
JOptionPane.showMessageDialog(window
“Something is wrong with a class used by “ +
“serialization.“ “Termination Error“JOptionPane.ERROR_MESSAGE );
shutDown();//退出程序
}
catch( StreamCorruptedException sce ){
JOptionPane.showMessageDialog(window
“Control information in the stream is “ +
“inconsistent.“ “Termination Error“JOptionPane.ERROR_MESSAGE );
shutDown();
}
catch( OptionalDataException ode ){
JOptionPane
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2011-06-14 19:14 chatProgram\
文件 301 2011-06-14 18:56 chatProgram\.classpath
文件 387 2011-06-14 18:56 chatProgram\.project
目录 0 2011-06-14 19:14 chatProgram\.settings\
文件 629 2011-06-14 18:56 chatProgram\.settings\org.eclipse.jdt.core.prefs
目录 0 2011-06-14 19:14 chatProgram\bin\
目录 0 2011-06-14 19:14 chatProgram\bin\chat\
文件 2905 2011-06-14 18:56 chatProgram\bin\chat\ChatClient$InputListener.class
文件 6276 2011-06-14 18:56 chatProgram\bin\chat\ChatClient.class
文件 6040 2011-06-14 18:56 chatProgram\bin\chat\ChatServer$ChatHandler.class
文件 4788 2011-06-14 18:56 chatProgram\bin\chat\ChatServer.class
文件 1024 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$AboutHlpMenu.class
文件 702 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$CloseAllTabsMenu.class
文件 1345 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$CloseTabButton.class
文件 832 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$ConfigureFMenu.class
文件 841 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$ConfigureServerInfo$CancelButton.class
文件 1314 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$ConfigureServerInfo$SaveButton.class
文件 2932 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$ConfigureServerInfo.class
文件 2268 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$ConnectFMenu.class
文件 844 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$DisconnectFMenu.class
文件 769 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$ExitButton.class
文件 943 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$FocusMessageField.class
文件 651 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$HelpHlpMenu.class
文件 973 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$OnExit.class
文件 1129 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$SelectClient.class
文件 799 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$SendButton.class
文件 686 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$SendMessage.class
文件 993 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface$WebHlpMenu.class
文件 9399 2011-06-14 18:56 chatProgram\bin\chat\ClientInterface.class
文件 994 2011-06-14 18:56 chatProgram\bin\chat\ServerInterface$AboutHlpMenu.class
文件 802 2011-06-14 18:56 chatProgram\bin\chat\ServerInterface$clientSelected.class
............此处省略38个文件信息
相关资源
- 微博系统(Java源码,servlet+jsp),适
- java串口通信全套完整代码-导入eclip
- jsonarray所必需的6个jar包.rar
- 三角网构TIN生成算法,Java语言实现
- java代码编写将excel数据导入到mysql数据
- Java写的cmm词法分析器源代码及javacc学
- JAVA JSP公司财务管理系统 源代码 论文
- JSP+MYSQL旅行社管理信息系统
- 推荐算法的JAVA实现
- 基于Java的酒店管理系统源码(毕业设
- java-图片识别 图片比较
- android毕业设计
- java23种设计模式+23个实例demo
- java Socket发送/接受报文
- JAVA828436
- java界面美化 提供多套皮肤直接使用
- 在线聊天系统(java代码)
- 基于Java的图书管理系统807185
- java中实现将页面数据导入Excel中
- java 企业销售管理系统
- java做的聊天系统(包括正规课程设计
- Java编写的qq聊天室
- 商店商品管理系统 JAVA写的 有界面
- JAVA开发聊天室程序
- 在linux系统下用java执行系统命令实例
- java期末考试试题两套(答案) 选择(
- JAVA3D编程示例(建模、交互)
- Java 文件加密传输
- java做的房产管理系统
- 基于jsp的bbs论坛 非常详细
评论
共有 条评论