局域网聊天室--java课程设计Word下载.docx

上传人:wj 文档编号:726958 上传时间:2023-04-29 格式:DOCX 页数:98 大小:198.08KB
下载 相关 举报
局域网聊天室--java课程设计Word下载.docx_第1页
第1页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第2页
第2页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第3页
第3页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第4页
第4页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第5页
第5页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第6页
第6页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第7页
第7页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第8页
第8页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第9页
第9页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第10页
第10页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第11页
第11页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第12页
第12页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第13页
第13页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第14页
第14页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第15页
第15页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第16页
第16页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第17页
第17页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第18页
第18页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第19页
第19页 / 共98页
局域网聊天室--java课程设计Word下载.docx_第20页
第20页 / 共98页
亲,该文档总共98页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

局域网聊天室--java课程设计Word下载.docx

《局域网聊天室--java课程设计Word下载.docx》由会员分享,可在线阅读,更多相关《局域网聊天室--java课程设计Word下载.docx(98页珍藏版)》请在冰点文库上搜索。

局域网聊天室--java课程设计Word下载.docx

四、要求的设计(调查/论文)成果

1.课程设计报告

2.课程设计软件

五、进程安排

布置任务,查找资料、需求分析1天

总体设计1天

详细设计1.5天

编制源程序实现3.5天

测试与修改1天

撰写课设报告2天

六、主要参考资料

[1]张广彬.Java课程设计案例精编(第二版).北京:

清华大学出版社,2011.

[2]耿祥义.Java课程设计(第二版).北京:

清华大学出版社,2008.

[3]耿祥义.JAVA大学实用教程.北京:

[4]邹林达.陈国君Java2程序设计基础.北京:

清华大学出版社,2010.

[5]邹林达.Java2程序设计基础实验指导.北京:

清华大学,2010.

指导教师(签名):

20

目录

1需求与总体设计 1

1.1需求与系统功能图 1

1.2系统类图 2

1.2.1服务端系统 2

1.2.2客户端服务系统 3

2详细设计 4

2.1聊天室服务器端的设计 4

2.1.1ChatServer类 4

2.1.2ServerListen类 5

2.1.3ServerReceive类 5

2.1.4PortConf类 6

2.1.5Help类 6

2.1.6UserLinkList类 7

2.1.7Node类 7

2.2聊天室客户端设计 8

2.2.1ChatClient类 8

2.2.2ConnectConf类 9

2.2.3UserConf类 9

2.2.4Help类 10

2.2.5ClientReceive类 10

3编码实现 11

3.1服务器编码实现 11

3.1.1ChatServer类 11

3.1.2ServerListen类 21

3.1.3ServerReceive类 23

3.1.4PortConf类 27

3.1.5UserLinkList类 30

3.1.6Node类 31

3.1.7Help类 32

3.2客户端编码实现 34

3.2.1ChatClient类 34

3.2.2ClientReceive类 46

3.2.3ConnectConf类 48

3.2.4UserConf类 51

3.2.5Hlep类 54

4系统测试 56

总结 57

退

停止服务

系统消息

启动服务

端口设置

1需求与总体设计

1.1需求与系统功能图

服务端

本系统所要实现的主要功能是为广大用户提供一个借助网络进行人际交往的平台。

因为服务端采用多线程,所以性能有很大提升。

因为服务端和客户端之间采用TCP协议进行网络通信,建立的是可靠的、端到端的网络连接,所以可靠性和安全性都很好。

退 出

用户连接

连接设置

登 录

发送消息

注 销

客户端

1.2系统类图

1.2.1

服务端系统

1

93

1.2.2客户端服务系统

2详细设计

2.1聊天室服务器端的设计

2.1.1ChatServer类

ChatServer.java

包含名为ChatServer的public类,其主要功能为定义服务器端的界面,添加时间监听与时间处理。

调用ServerListen类来实现服务端用户上线与下线的监听,调用

ServerListen来实现服务器端的消息收发。

2.1.2ServerListen类

ServerListen.java

该类实现服务器用户上线与下线的监听。

该类对用户上线下线的监听是通过调用用户链表类(UserLinkList)来实现的。

当用户上线与下线情况发生变化时,该类会对主类的界面进行相应的修改。

2.1.3ServerReceive类

ServerReceive.java

该类是实现服务器消息收发的类,该类分别定义了向某用户及所有人发送消息的方法,发送的消息会显示在主界面类的街面上。

2.1.4PortConf类

PortConf.java

该类继承自Jdialog,是用户对服务器端监听端口进行修改配置的类。

2.1.5Help类

Help.java

服务端程序帮助类。

2.1.6UserLinkList类

UserLinkList.java

用户链表节点的具体实现类。

该类通过构造函数构造用户链表,定义了添加用户、删除用户、返回用户数、根据用户名查找用户、根据索引查找用户这5个方法。

2.1.7Node类

Node.java

用户链表的节点类,定义了链表中的用户。

该类与前面所讲的链表节点Node类的功能相当

2.2聊天室客户端设计

2.2.1ChatClient类

ChatClient.java

包含名为ChatClient的public类,其主要功能为定义客户端的界面,添加时间监听与事件处理。

该类定义了Connect()与DisConnect()方法实现与客户端的连接与断开连接。

当登陆到指定的服务器时,调用ClientReceive类实现消息收发,同时该类还定义了SendMessaga()方法来其他用户发送带有表情的消息或悄悄话。

2.2.2ConnectConf类

ConnectConf.java

该类继承自Jdialog,是用户对所有要连接的服务器IP及监听端口进行修改配置的类。

2.2.3UserConf类

UserConf.java

该类继承自Jdialog,是用户对链接到服务器时所显示的用户名进行修改配置的类。

2.2.4Help类

客户端程序的帮助类。

2.2.5ClientReceive类

ClientReceive.java

该类是实现服务器端与客户端消息收发的类。

3编码实现

3.1服务器编码实现

3.1.1ChatServer类

调用ServerListen类来实现服务端用户上线与下线的监听,调用ServerListen来实现服务器端的消息收发。

/*聊天服务端的主框架类*/

publicclassChatServerextendsJFrameimplementsActionListener{privatestaticfinallongserialVersionUID=1L;

publicstaticintport=8888;

//服务端的侦听端口

ServerSocketserverSocket;

//服务端SocketJComboBoxcombobox;

//选择发送消息的接受者JTextAreamessageShow;

//服务端的信息显示JScrollPanemessageScrollPane;

//信息显示的滚动条JTextFieldshowStatus;

//显示用户连接状态

JLabelsendToLabel,messageLabel;

JTextFieldsysMessage;

//服务端消息的发送

JButtonsysMessageButton;

//服务端消息的发送按钮UserLinkListuserLinkList;

//用户链表

//建立菜单栏

JMenuBarjMenuBar=newJMenuBar();

//建立菜单组

JMenuserviceMenu=newJMenu("

服务(V)"

);

//建立菜单项

JMenuItemportItem=newJMenuItem("

端口设置(P)"

JMenuItemstartItem=newJMenuItem("

启动服务(S)"

JMenuItemstopItem=newJMenuItem("

停止服务(T)"

JMenuItemexitItem=newJMenuItem("

退出(X)"

JMenuhelpMenu=newJMenu("

帮助(H)"

JMenuItemhelpItem=newJMenuItem("

//建立工具栏

JToolBartoolBar=newJToolBar();

//建立工具栏中的按钮组件JButtonportSet;

//启动服务端侦听

JButtonstartServer;

//启动服务端侦听JButtonstopServer;

//关闭服务端侦听JButtonexitButton;

//退出按钮

//框架的大小

DimensionfaceSize=newDimension(400,600);

ServerListenlistenThread;

JPaneldownPanel;

GridBagLayoutgirdBag;

GridBagConstraintsgirdBagCon;

/**服务端构造函数*/

publicChatServer(){

init();

//初始化程序

//添加框架的关闭事件处理this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

this.pack();

//设置框架的大小

this.setSize(faceSize);

//设置运行时窗口的位置

DimensionscreenSize=Toolkit.getDefaultToolkit().getScreenSize();

this.setLocation((int)(screenSize.width-faceSize.getWidth())/2,

(int)(screenSize.height-faceSize.getHeight())/2);

this.setResizable(false);

this.setTitle("

聊天室服务端"

//设置标题

setVisible(true);

//为服务菜单栏设置热键'

V'

serviceMenu.setMnemonic('

//为端口设置快捷键为ctrl+p

portItem.setMnemonic('

P'

portItem.setAccelerator

(KeyStroke.getKeyStroke(KeyEvent.VK_P,InputEvent.CTRL_MASK));

//为启动服务快捷键为ctrl+s

startItem.setMnemonic('

S'

startItem.setAccelerator(KeyStroke.getKeyStroke

(KeyEvent.VK_S,InputEvent.CTRL_MASK));

//为端口设置快捷键为ctrl+TstopItem.setMnemonic('

T'

stopItem.setAccelerator(KeyStroke.getKeyStroke

(KeyEvent.VK_T,InputEvent.CTRL_MASK));

//为退出设置快捷键为ctrl+xexitItem.setMnemonic('

X'

exitItem.setAccelerator(KeyStroke.getKeyStroke

(KeyEvent.VK_X,InputEvent.CTRL_MASK));

//为帮助菜单栏设置热键'

H'

helpMenu.setMnemonic('

//为帮助设置快捷键为ctrl+p

helpItem.setMnemonic('

helpItem.setAccelerator(KeyStroke.getKeyStroke

(KeyEvent.VK_H,InputEvent.CTRL_MASK));

}

/***程序初始化函数*/publicvoidinit(){

ContainercontentPane=getContentPane();

contentPane.setLayout(newBorderLayout());

//添加菜单栏serviceMenu.add(portItem);

serviceMenu.add(startItem);

serviceMenu.add(stopItem);

serviceMenu.add(exitItem);

jMenuBar.add(serviceMenu);

helpMenu.add(helpItem);

jMenuBar.add(helpMenu);

setJMenuBar(jMenuBar);

//初始化按钮

portSet=newJButton("

端口设置"

startServer=newJButton("

启动服务"

stopServer=newJButton("

停止服务"

);

exitButton=newJButton("

退出"

//将按钮添加到工具栏toolBar.add(portSet);

toolBar.addSeparator();

//添加分隔栏

toolBar.add(startServer);

toolBar.add(stopServer);

toolBar.add(exitButton);

contentPane.add(toolBar,BorderLayout.NORTH);

//初始时,令停止服务按钮不可用

stopServer.setEnabled(false);

stopItem.setEnabled(false);

//为菜单栏添加事件监听

portItem.addActionListener(this);

startItem.addActionListener(this);

stopItem.addActionListener(this);

exitItem.addActionListener(this);

helpItem.addActionListener(this);

//添加按钮的事件侦听

portSet.addActionListener(this);

startServer.addActionListener(this);

stopServer.addActionListener(this);

exitButton.addActionListener(this);

combobox=newJComboBox();

combobox.insertItemAt("

所有人"

0);

combobox.setSelectedIndex(0);

messageShow=newJTextArea();

messageShow.setEditable(false);

//添加滚动条

messageScrollPane=newJScrollPane(messageShow,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

messageScrollPane.setPreferredSize(newDimension(400,400));

messageScrollPane.revalidate();

showStatus=newJTextField(35);

showStatus.setEditable(false);

sysMessage=newJTextField(24);

sysMessage.setEnabled(false);

sysMessageButton=newJButton();

sysMessageButton.setText("

发送"

//添加系统消息的事件侦听sysMessage.addActionListener(this);

sysMessageButton.addActionListener(this);

sendToLabel=newJLabel("

发送至:

"

messageLabel=newJLabel("

发送消息:

downPanel=newJPanel();

girdBag=newGridBagLayout();

downPanel.setLayout(girdBag);

girdBagCon=newGridBagConstraints();

girdBagCon.gridx=0;

girdBagCon.gridy=0;

girdBagCon.gridwidth=3;

girdBagCon.gridheight=2;

girdBagCon.ipadx=5;

girdBagCon.ipady=5;

JLabelnone=newJLabel("

"

girdBag.setConstraints(none,girdBagCon);

downPanel.add(none);

girdBagCon=newGridBagConstraints();

girdBagCon.gridy=2;

girdBagCon.insets=newInsets(1,0,0,0);

girdBagCon.ipadx=5;

girdBag.setConstraints(sendToLabel,girdBagCon);

downPanel.add(sendToLabel);

girdBagCon.gridx=1;

girdBagCon.anchor=GridBagConstraints.LINE_START;

girdBag.setConstraints(combobox,girdBagCon);

downPanel.add(combobox);

girdBagCon.gridy=3;

girdBag.setConstraints(messageLabel,girdBagCon);

downPanel.add(messageLabel);

girdBagCon.gridx=1;

girdBag.setConstraints(sysMessage,girdBagCon);

downPanel.add(sysMessage);

girdBagCon.gridx=2;

girdBag.setConstraints(sysMessageButton,girdBagCon);

downPanel.add(sysMessageButton);

girdBagCon.gridy=4;

girdBag.setConstraints(showStatus,girdBagCon);

downPanel.add(showStatus);

contentPane.add(messageScrollPane,BorderLayout.CENTER);

contentPane.add(downPanel,BorderLayout.SOUTH);

//关闭程序时的操作

this.addWindowListener(newWindowAdapter(){

publicvoidwindowClosing(WindowEvente){stopService();

System.exit(0);

/***事件处理*/

publicvoidactionPerformed(ActionEvente){

Objectobj=e.getSource();

if(obj==startServer||obj==startItem){//启动服务端startService();

elseif(obj==stopServer||obj==stopItem){//停止服务端intj=JOptionPane.showConfirmDialog(

this,"

真的停止服

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > PPT模板 > 简洁抽象

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2