学院面向对象程序设计实训分析报告

上传人:zejun11****63.com 文档编号:122146404 上传时间:2020-03-02 格式:DOC 页数:108 大小:1.39MB
返回 下载 相关 举报
学院面向对象程序设计实训分析报告_第1页
第1页 / 共108页
学院面向对象程序设计实训分析报告_第2页
第2页 / 共108页
学院面向对象程序设计实训分析报告_第3页
第3页 / 共108页
学院面向对象程序设计实训分析报告_第4页
第4页 / 共108页
学院面向对象程序设计实训分析报告_第5页
第5页 / 共108页
点击查看更多>>
资源描述

《学院面向对象程序设计实训分析报告》由会员分享,可在线阅读,更多相关《学院面向对象程序设计实训分析报告(108页珍藏版)》请在金锄头文库上搜索。

1、 广西科技大学鹿山学院广西科技大学鹿山学院 面向对象程序设计实训报告面向对象程序设计实训报告 题 目 网络中国象棋 系 不 电气与计算机工程系 专业班级 计软 141 班 姓 名 邓康言 学 号 20141409 成绩评定 指导教师签字 2016 年 1 月 10 日 1 109 目录 目录目录 1 需求分析 1 1 1 开发的背景 1 1 2 算法 1 1 3 要求 1 2 总体分析与设计 1 2 1 总体设计方案 1 2 2 功能描述 2 2 2 1 服务器端 2 2 2 2 客户端 2 2 32 3 算法设计算法设计 3 2 52 5 系统流程图系统流程图 4 3 数据结构设计 4 3

2、1 功能模块的设计 4 2 109 3 1 1 服务器端框架类设计 4 3 1 2 服务器线程设计 8 3 1 3 服务器代理线程设计 8 3 1 4 棋子的开发类设计 13 3 1 5 客户端的框架类设计 14 3 1 6 客户端的框架类设计 16 3 1 7 棋子的规则类设计 19 3 1 8 棋盘的规则类设计 22 4 系统实现 26 4 1 服务器端界面 26 4 2 客户端界面 26 4 3 未启动服务器 客户端连接失败 27 4 4 服务器启动 27 4 5 服务器启动客户端成功连接 28 4 6 显示在线用户 28 3 109 4 7 不同意重名 29 4 8 发起挑战 29 4

3、 9 拒绝挑战 30 4 10 同意挑战 30 4 11 对战走棋 31 4 12 不能向正在下棋的用户发起挑战 31 4 13 赢棋 32 4 14 认输 32 4 15 服务器关闭 33 总 结 33 参考文献参考文献 34 1 1 需求分析需求分析 4 109 1 1 开发的背景 中国象棋有着悠久的历史 象棋爱好者更是不计其数 然而 由于人们的工作地点从 时刻的限制 原始的那种面对面的 下棋方式差不多不再适应人们的生活 人们差不多开始走向 网络象棋博弈 网络象棋有着专门多的优点 通过网络象棋 对弈的双方是 网络上任意的两个象棋爱好者 甚至是不认识 网络让对弈 的范围更加的广泛 让象棋爱好

4、者能够与更多的象棋爱好者 切磋棋艺 1 2 算法 指定服务器端口号 支持多人同时在线 显示在线用户信息 显示当前在线所有用户 从在线用户列表中选择玩家进行挑战 5 109 同意或拒绝挑战 1 3 要求 用 Java 语言实现系统 源程序要有适当的注释 使程序容易 阅读 函数功能要划分好 结构化程序设计 能够增加新功能模块 2 2 总体分析与设计总体分析与设计 6 109 2 1 总体设计方案 系统功能模块图 7 109 2 2 功能描述 2 2 1 服务器端 能够指定服务器端口号 能够支持多人同时在线 能够显示在线用户信息 不同意玩家同名 2 2 2 客户端 能够通过主机 IP 号及端口号登陆

5、到服务器 能够显示当前在线所有用户 能够从在线用户列表中选择玩家进行挑战 能够同意或拒绝挑战 假如对方在和其他玩家对弈中 则应该给与相应 的提示信息 象棋规则一定要严密 棋子样式采纳最一般的橡胶式象棋 棋子为黑色 字为红色和白色 2 32 3 算法设计算法设计 本程序功能模块依照程序设计的需要 综合程序的有用性 智能化的考虑 将程序划分为 8 个模块来写 8 109 1 服务器端的框架设计类 2 服务器线程类 3 服务器代理线程类 4 棋子类的开发类 5 客户端的框架设计类 6 客户端线程类 7 棋子的规则类 8 棋盘的设计类 9 109 2 52 5 系统流程图系统流程图 3 3 数据结构设

6、计数据结构设计 10 109 3 1 功能模块的设计 3 1 1 服务器端框架类设计 importimport java util importimport java awt 界面包 importimport java awt event 事件处理包 importimport javax swing 图形化界面包 importimport javax swing event 图形化界面包事件进行处理 importimport 网络包 importimport java io IO流 publicpublic classclass Server extendsextends JFrame imp

7、lementsimplements ActionListener JLabel jlPort newnew JLabel 端 口 号 创建提示输入端口 号标签 JTextField jtfPort newnew JTextField 9457 用于输入端口 11 109 号的文本框 JButton jbStart newnew JButton 启动 创建 启动 按钮 JButton jbStop newnew JButton 关闭 创建 关闭 按钮 JPanel jps newnew JPanel 创建一个JPanel对象 JList jlUserOnline newnew JList 创建用

8、于显示当前用户的 JList JScrollPane jspx newnew JScrollPane jlUserOnline 将显示 当前用户的JList放在JScrollPane中 JSplitPane jspz newnew JSplitPane JSplitPane HORIZONTAL SPLITHORIZONTAL SPLIT jspx jps 创建 JSplitPane对象 ServerSocket ss 声明ServerSocket引用 ServerThread st 声明ServerThread引用 Vector onlineList newnew Vector 创建存放当前

9、在线用户的 Vector对象 12 109 publicpublic Server thisthis initialComponent 初始化控件 thisthis addListener 为相应的控件注册事件监听器 thisthis initialFrame 初始化窗体 thisthis setDefaultCloseOperation JFrame EXIT ON CLOSEEXIT ON CLOSE publicpublic voidvoid initialComponent jps setLayout nullnull 设为空布局 jlPort setBounds 20 20 50 2

10、0 jps add jlPort 添加用于提示输入端口号的标签 thisthis jtfPort setBounds 85 20 60 20 jps add thisthis jtfPort 添加用于输入端口号的文本框 thisthis jbStart setBounds 18 50 60 20 13 109 jps add thisthis jbStart 添加 开始 按钮 thisthis jbStop setBounds 85 50 60 20 jps add thisthis jbStop 添加 关闭 按钮 thisthis jbStop setEnabled falsefalse 将

11、 关闭 按钮设为不可 用 publicpublic voidvoid addListener thisthis jbStart addActionListener thisthis 为 开始 按钮注 册事件监听器 thisthis jbStop addActionListener thisthis 为 关闭 按钮注 册事件监听器 publicpublic voidvoid initialFrame 14 109 thisthis setTitle 象棋 服务器端 设置窗体标题 Image image newnew ImageIcon ico gif getImage thisthis setI

12、conImage image thisthis add jspz 将JSplitPane添加到窗体中 jspz setDividerLocation 250 jspz setDividerSize 4 设置分割线的位置和宽度 thisthis setBounds 20 20 420 320 thisthis setVisible truetrue 设置可见性 thisthis addWindowListener 为窗体关闭事件注册监听器 newnew WindowAdapter publicpublic voidvoid windowClosing WindowEvent e ifif st

13、nullnull 当服务器线程为空时直接退出 15 109 System exit 0 退出 returnreturn trytry Vector v onlineList intint size v size forfor intint i 0 i size i 当不为空时 向在线用户发送离线信息 ServerAgentThread tempSat ServerAgentThread v get i tempSat dout writeUTF tempSat flag falsefalse 终止服务器代理线程 16 109 st flag falsefalse 终止服务器线程 st null

14、null ss close 关闭ServerSocket v clear 将在线用户列表清空 refreshList 刷新列表 catchcatch Exception ee ee printStackTrace System exit 0 退出 17 109 publicpublic voidvoid actionPerformed ActionEvent e ifif e getSource thisthis jbStart 当单击 启动 按钮时 thisthis jbStart event elseelse ifif e getSource thisthis jbStop 单击 关闭 按

15、钮后 thisthis jbStop event publicpublic voidvoid jbStart event 单击 启动 按钮的业务处理代码 18 109 intint port 0 trytry 获得用户输入的端口号 并转化为整型 port Integer parseInt thisthis jtfPort getText trim catchcatch Exception ee 端口号不是整数 给出提示信息 JOptionPane showMessageDialog thisthis 端口号只能是整 数 错误 JOptionPane ERROR MESSAGEERROR MES

16、SAGE returnreturn 19 109 ifif port 65535 port 0 断口号不合法 给出提示信息 JOptionPane showMessageDialog thisthis 端口号只能是0 65535的整数 错误 JOptionPane ERROR MESSAGEERROR MESSAGE returnreturn trytry thisthis jbStart setEnabled falsefalse 将开始按钮设为不 可用 thisthis jtfPort setEnabled falsefalse 将用于输入端口号 的文本框设为不可用 thisthis jbStop setEnabled truetrue 将停止按钮设为可用 20 109 ss newnew ServerSocket port 创建ServerSocket对象 st newnew ServerThread thisthis 创建服务器线程 st start 启动服务器线程 给出服务器启动成功的提示信息 JOptionPane showMessageDialog thisthis 服务

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号