教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 精品文档 > 说明书 >

聊天室的实现与设计(8)

来源:网络收集 时间:2025-09-14
导读: 兰州交通大学博文学院毕业设计(论文) } Transaction trans=session.beginTransaction(); session.save(inf); trans.commit(); session.close(); 5.4 客户端模块功能实现 图 6-4 客户端界面 客户端时用户聊天的主

兰州交通大学博文学院毕业设计(论文)

}

Transaction trans=session.beginTransaction(); session.save(inf); trans.commit(); session.close();

5.4 客户端模块功能实现

图 6-4 客户端界面

客户端时用户聊天的主功能界面,用户登陆后可以实现发送公聊信息、发送私聊信息、接受服务器发送的系统信息;用户也可以对系统消息、个人聊天记录、在线用户信息进行查询,并且可以对个人注册信息进行修改以及删除个人聊天记录。 5.4.1 客户端接受信息功能实现 public void run() {

if (type.equalsIgnoreCase(\系统信息]\)) {

String sysMsg = (String) input.readObject();

if (sysMsg.equalsIgnoreCase(\用户名已被使用\)) {// 若登陆

while (!isStop) {

try {

String type = (String) input.readObject();// 读取信息类型

用户名称已被使用,则停止当前登陆用记信息接收线程

C.logOut();

textArea.append(\系统信息]\ + sysMsg + \); break;

31

兰州交通大学博文学院毕业设计(论文)

}

if (sysMsg.equalsIgnoreCase(\服务器关闭!\)) { }

if (sysMsg.equalsIgnoreCase(\踢出\)) {

C.logOut(); textArea

.append(\系统信息]你违反了本聊天室规则.\\n[系统

C.logOut();

textArea.append(\服务器已关闭!\\n\); break;

信息]被管理员踢出了聊天室.\\n\);

}

textArea.append(\系统信息]\ + sysMsg);

break;

} else if (type.equalsIgnoreCase(\聊天信息]\)) {

String message = type.trim() + (String) input.readObject(); textArea.append(message);

} else if (type.equalsIgnoreCase(\用户列表]\)) {

String userList = (String) input.readObject(); String userNames[] = userList.split(\); comboBox.removeAllItems(); int i = 0;

comboBox.addItem(\大家\); while (i < userNames.length) { }

comboBox.setSelectedIndex(0);

comboBox.addItem(userNames[i]); i++;

} else if (type.equalsIgnoreCase(\在线用户]\)) {

String sysMsg = type.trim() + (String) input.readObject();

32

兰州交通大学博文学院毕业设计(论文)

} catch (Exception e) { }

}

textField.setText(sysMsg);

5.4.2 客户端发送消息功能实现 public void SendMessage() {

String toSomebody = comboBoxUserList.getSelectedItem().toString(); String status = \; if (socket.isClosed())

return;

if (checkBox.isSelected())

status = \悄悄话\;

String action = comboBoxAction.getSelectedItem().toString(); String content = sendMessage.getText(); Date sendDate=new Date();

Message message=new Message(); message.setContent(content); message.setSendid(userId); message.setSendDate(sendDate); message.setSendToSomebody(toSomebody); try {

ServerServiceImp.saveMessage(message);

System.out.println(\); output.writeObject(\聊天信息]\); output.flush();

output.writeObject(toSomebody); output.flush();

output.writeObject(status);

33

兰州交通大学博文学院毕业设计(论文)

}

output.flush();

output.writeObject(action); output.flush();

output.writeObject(content); output.flush();

} catch (Exception e) { }

5.4.3 查询系统信息功能实现 //对系统消息的查找

public static String getInformation() { }

UserDAOOper oper=OperatorFactory.getUserOperator(); List list=oper.loadInformation(); if(list==null)

return \;

String infStr=\;

Date sendDate=new Date(); for(Information inf:list) { }

return infStr;

sendDate=inf.getSendDate(); String content=inf.getContent(); infStr+=\系统消息\+\

+sendDate.toString()+\ +content+\;

5.4.4 查询聊天记录功能实现

public static String getMessage(Long userid){

34

兰州交通大学博文学院毕业设计(论文)

}

UserDAOOper oper=OperatorFactory.getUserOperator(); List list=oper.loadMessages(userid); if(list==null){ }

String message=\; Date sendDate=new Date(); for(Message me:list){ }

return message;

sendDate=me.getSendDate(); String content=me.getContent(); List user=oper.load(userid);

String userName=user.get(0).getUserName(); String sendToSomebody=me.getSendToSomebody(); message+=\聊天记录\+\

+sendDate.toString()+\ +userName+\对\

+sendToSomebody+\说\+\ +content +\ +\;

return \没有相关记录\;

5.4.5 用户资料查询功能实现 //查找个人信息

public static String getDescription(String userName) {

UserDAOOper oper=OperatorFactory.getUserOperator(); Long id=null;

id=oper.load(userName).get(0).getId();

35

…… 此处隐藏:1508字,全部文档内容请下载后查看。喜欢就下载吧 ……
聊天室的实现与设计(8).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wendang/449201.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)