




已阅读5页,还剩18页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
网络程序设计(Java)课程设计报告题 目: 记忆测试程序 系 别: 电子信息工程系 专业名称: 信息安全技术 班 级: 信息安全101 学 号: 020708102 姓 名: 蔡少聪 指导教师: 林建兵 二一二年六月目录1、 系统简介-32、 需求分析-3 2.1、系统设计内容及要求-3 2.2、系统设计步骤-33、 概要设计-4 3.1、程序类说明-4 3.2、程序类源文件及功能-4 3.3、程序流程图-54、 详细设计-5 4.1、主类的代码设计-5五、系统测试效果-14 5.1游戏界面图-14 5.2游戏效果图-15六、系统设计总结心得-16一、 系统简介记忆测试系统主要通过逐级增加游戏方块来增加游戏难度,同时对测试者记忆能力的要求也越来越高。本测试系统分为初级、中级和高级。游戏中,测试者只有找到相应等级个数的相同方块才能过关,即连续选中相应个数的相同方块。记忆测试系统利用容器和各个组件之间的嵌套完成系统的主要框架的设计,为各个容器添加相应的组件,并结合对各组件的事件的监听以及事件的处理,实现本系统的功能要求。 二、 需求分析2.1 系统设计内容及要求1) 、游戏说明2) 、系统相关说明3) 、游戏等级的设定,分为三个等级:初级、中级、高级4) 、游戏评分标准。游戏以时间做为游戏成绩记录方式,并以此评定游戏成绩5) 、游戏成绩排行,不同等级的游戏对应不同游戏排行榜2.2 系统设计步骤1) 、主类Memory2) 、方块 Block3) 、记忆测试板MemoryTestPane4) 、显示成绩 ShowRecord5) 、记录成绩 Record6) 、随机排列图标 RandomSetIcon7) 、测试者 People三、 概要设计3.1程序类说明 记忆测试系统界面:主框架界面Memory ,继承的父类JFrame,组件框架方块类Block,继承的父类JButton,测试面板类MemoryTestPane,继承父类JPanel,记录类Record,继承父类JFrame,定义帮助、提示类ShowHelp,继承父类JDialog,随机排布类RandomSetIcon,测试者类People,记录显示类ShowRecord,继承父类JDialog。成绩记录文档,分别为初级记忆排行榜.txt、中级记忆排行榜.txt高级记忆排行榜.txt。*public class Memory extends JFrame implements ActionListener *public class Block extends JButton implements ActionListener*public class MemoryTestPane extends JPanel implements ActionListener*public class People implements java.io.Serializable*public class RandomSetIcon *public class Record extends JFrame implements ActionListener*public class ShowHelp extends JDialog*public class ShowRecord extends JDialog implements ActionListener3.2、程序类源文件以及功能1) 、Memory.javaMemory类定义了记忆测试系统的主窗口,包括整体窗口的布局。该类含有main主函数,记忆测试系统程序从该类开始执行。Memory类包括String、File、MemoryTestPane、ShowRecord四大主要类型对象。2) 、MemoryTestPane.javaMemoryTestPane该类是主类Memory类窗口中的一个JPanel容器,所创建的对象称为测试区,这个测试区被添加到Memory类窗口的中心。该类主要有6中类型对象:Block、String、Record、Timer、File、Therad。3) 、Block.javaBlock类是Jbutton类的子类负责为MemoryTestPane类中的Block数组表提供Block对象。4) 、Record.javaRecord.类是javax.swing包中Jdialog对话框的子类,当用户成功单击出相应级别所要求的图标相同的方块后,Record类创建的对象负责保存用户的名字和成绩到相应的级别文件中。5) 、ShowRecord.javaShowRecord类是javax.swing包中Jdialog对话框的子类,当用户成功单击相应级别的“查看排行榜”的时候,ShowRecord类负责显示相应级别用户的成绩。6) 、RandomSetIcon.javaRandomSetIcon.类是javax.swing包中Jdialog对话框的子类,该类主要负责随机产生并排列主窗口中的游戏图标,以防每次都是相同的图案顺序。7) 、People.javaPeople类封装用户的名字和成绩,以便ShowRecord类对象可以按成绩高低排序用户。3.3程序流程图开始高级初级 中级高级:m=7,n=8初级:m=5,n=6显示游戏面板中级:m=6,n=7 功能选择重新游戏正常游戏游戏继续菜单栏游戏暂停是否记录成绩等级排行榜帮助等级选择记录到相应榜单评分标准游戏规则关于初级排行榜高级排行榜中级排行榜测试游戏结束关闭Memory4、 详细设计4.1、主类的代码设计1) 、Memory.javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.LinkedList;public class Memory extends JFrame implements ActionListener JMenuBar bar; JScrollPane scrollHelp; ShowHelp showabout=null; JMenu fileMenu,helpMenu; JMenuItem junior,middle,senior,juniortaxis,middletaxis,seniortaxis,help,about; String s1=初级:您需要连续找到6个相同的图标; String s2=初级:您需要连续找到7个相同的图标; String s3=初级:您需要连续找到8个相同的图标; Block block; ImageIcon icon; MemoryTestPane memorytestpane=null; File juniorfile=new File(初级记忆排行榜.txt), middlefile=new File(中级记忆排行榜.txt), seniorfile=new File(高级记忆排行榜.txt); LinkedList marksheet=null; ShowRecord showrecord=null; int m=5,n=6; int k=0; Container con=null; JTextField textcue=null; JTextArea helptext; File gradeFile=null; public Memory() block=new Blockm*n; k=m; icon=new ImageIconk; for(int i=0;iicon.length;i+) iconi=new ImageIcon(a+i+.gif); for(int i=0;iblock.length;i+) blocki=new Block(); blocki.setcloseIcon(new ImageIcon(close.gif); bar=new JMenuBar(); fileMenu=new JMenu(记忆力测试); helpMenu=new JMenu(帮助); junior=new JMenuItem(初级); middle=new JMenuItem(中级); senior=new JMenuItem(高级); seniortaxis=new JMenuItem(高级排行榜); middletaxis=new JMenuItem(中级排行榜); juniortaxis=new JMenuItem(初级排行榜); help=new JMenuItem(游戏规则); about=new JMenuItem(关于); helptext = new JTextArea(5, 20); scrollHelp = new JScrollPane(helptext); helptext.setEditable(false); helptext.append( 本程序是使用说明n); helptext.append(1. 本游戏默认的是初级游戏n); helptext.append(2. 如果你想要玩中级和高级的请从记忆力测试菜单中选择。n); helptext.append(3. 不同等级的游戏要求不一样。n); helptext.append(4. 初级的要求连续找到6个相同的图标。n); helptext.append(5. 游戏结束后会有记录并要求录入测试者姓名。n); helptext.append(6. 如果要程序经多人玩后游戏会自动排名。n); fileMenu.add(junior); fileMenu.add(middle); fileMenu.add(senior); fileMenu.add(juniortaxis); fileMenu.add(middletaxis); fileMenu.add(seniortaxis); helpMenu.add(help); helpMenu.add(about); bar.add(fileMenu); bar.add(helpMenu); setJMenuBar(bar); junior.addActionListener(this); middle.addActionListener(this); senior.addActionListener(this); juniortaxis.addActionListener(this); middletaxis.addActionListener(this); seniortaxis.addActionListener(this); help.addActionListener(this); about.addActionListener(this); marksheet=new LinkedList(); if(!juniorfile.exists() try FileOutputStream out=new FileOutputStream(初级记忆排行榜.txt); ObjectOutputStream object_out=new ObjectOutputStream(out); object_out.writeObject(marksheet); object_out.close(); out.close(); catch(IOException e) if(!middlefile.exists() try FileOutputStream out=new FileOutputStream(中级记忆排行榜.txt); ObjectOutputStream object_out=new ObjectOutputStream(out); object_out.writeObject(marksheet); object_out.close(); out.close(); catch(IOException e) if(!seniorfile.exists() try FileOutputStream out=new FileOutputStream(高级记忆排行榜.txt); ObjectOutputStream object_out=new ObjectOutputStream(out); object_out.writeObject(marksheet); object_out.close(); out.close(); catch(IOException e) gradeFile=juniorfile; setBounds(100,100,500,460); setVisible(true); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System.exit(0); ); con=getContentPane(); memorytestpane=new MemoryTestPane(block,icon,m,n,gradeFile); textcue=new JTextField(s1); textcue.setEditable(false); textcue.setForeground(Color.red); con.add(memorytestpane,BorderLayout.CENTER); con.add(textcue,BorderLayout.SOUTH); con.validate(); this.validate(); public void testgrade(int width,int high,File f) m=width; n=high; k=m; gradeFile=f; block=new Blockm*n; icon=new ImageIconk; for(int i=0;iicon.length;i+) iconi=new ImageIcon(a+i+.gif); for(int i=0;iblock.length;i+) blocki=new Block(); blocki.setcloseIcon(new ImageIcon(close.gif); memorytestpane=new MemoryTestPane(block,icon,m,n,gradeFile); con.removeAll(); con.add(memorytestpane,BorderLayout.CENTER); con.add(textcue,BorderLayout.SOUTH); con.validate(); this.validate(); public void actionPerformed(ActionEvent event) if(event.getSource()=junior) testgrade(5,6,juniorfile); setBounds(100,100,500,460); this.validate(); textcue.setText(s1); if(event.getSource()=middle) testgrade(6,7,middlefile); setBounds(100,100,600,530); this.validate(); textcue.setText(s2); if(event.getSource()=senior) testgrade(7,8,seniorfile); setBounds(100,100,670,600); this.validate(); textcue.setText(s3); if(event.getSource()=seniortaxis) showrecord=new ShowRecord(this,seniorfile); showrecord.setVisible(true); if(event.getSource()=middletaxis) showrecord=new ShowRecord(this,middlefile); showrecord.setVisible(true); if(event.getSource()=juniortaxis) showrecord=new ShowRecord(this,juniorfile); showrecord.setVisible(true); if(event.getSource()=help) JOptionPane.showMessageDialog(con, scrollHelp); if(event.getSource()=about) JOptionPane.showMessageDialog(con, 开发者:*); public static void main(String args) new Memory();2) 、MemoryTestPane.javaimport javax.swing.*; import java.awt.event.*;import java.awt.*;import java.util.LinkedList;import java.io.*;public class MemoryTestPane extends JPanel implements ActionListener RandomSetIcon sortImageIcon=null; Block block; ImageIcon icon; LinkedList listIocn=null, listBlock=null; int row=0,lie=0; int success=0; int w=1; int time=0; javax.swing.Timer timer=null; JTextField showtime=null; JButton pauze,kk; File gradeFile=null; boolean timerisstart=false; public MemoryTestPane(Block block,ImageIcon icon,int m,int n,File f) sortImageIcon=new RandomSetIcon(); this.block=block; this.icon=icon; row=m; lie=n; gradeFile=f; pauze=new JButton(); kk=new JButton(); kk.setText(继续游戏); kk.addActionListener(this); pauze.setText(暂停游戏); pauze.addActionListener(this); listIocn=new LinkedList(); listBlock=new LinkedList(); setLayout(new BorderLayout(); JPanel center=new JPanel(); center.setLayout(new GridLayout(row,lie); for(int i=0;iblock.length;i+) center.add(blocki); blocki.setImageIcon(blocki.getcloseIcon(); blocki.addActionListener(this); JPanel south=new JPanel(); showtime=new JTextField(12); showtime.setEditable(false); showtime.setForeground(Color.red); south.add(kk); south.add(showtime); south.add(pauze); add(center,BorderLayout.CENTER); add(south,BorderLayout.SOUTH); sortImageIcon.Iconrandom(block,icon); timer=new Timer(1000,this); timerisstart=false; public void actionPerformed(ActionEvent e) if(e.getSource()=pauze) timer.stop(); for(int i=0;iblock.length;i+) blocki.setEnabled(false); if(e.getSource()=kk) timer.start(); timerisstart=true; for(int i=0;iblock.length;i+) blocki.setEnabled(true); if(e.getSource() instanceof Block) Block g=(Block)e.getSource(); ImageIcon rollIcon=g.getrollIcon(); g.setImageIcon(rollIcon); if(listIocn.size()=0) listIocn.add(rollIcon); listBlock.add(g); success=1; else ImageIcon temp=(ImageIcon)listIocn.getLast(); if(temp=rollIcon&!(listBlock.contains(g) success=success+1; listIocn.add(rollIcon); listBlock.add(g); if(success=lie) for(int i=0;iblock.length;i+) blocki.setEnabled(false); for(int j=0;jlistBlock.size();j+) Block b=(Block)listBlock.get(j); b.setDisabledIcon(b.getrollIcon(); timer.stop(); Record record=new Record(gradeFile); record.setTime(time); record.setVisible(true); else if(temp!=rollIcon)&(!(listBlock.contains(g) listIocn.clear(); listBlock.clear(); listIocn.add(rollIcon); listBlock.add(g); success=1; for(int i=0;iblock.length;i+) if(g!=blocki) blocki.setImageIcon(blocki.getcloseIcon(); if(timerisstart=false) time=0; timer.start(); timerisstart=true; if(e.getSource()=timer) time=time+1; showtime.setText(您的用时:+time+秒); 3) 、Block.javaimport javax.swing.*;import java.awt.event.*;public class Block extends JButton implements ActionListener ImageIcon rollIcon=null,closeIcon=null; public Block() addActionListener(this); public ImageIcon getrollIcon() return rollIcon; public ImageIcon getcloseIcon() return closeIcon; public void setrollIcon(ImageIcon icon) rollIcon=icon; public void setcloseIcon(ImageIcon icon) closeIcon=icon; public void setImageIcon(ImageIcon icon) setIcon(icon); public void actionPerformed(ActionEvent e) this.setIcon(rollIcon); 4) 、Record.javaimport java.io.*;import java.util.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;public class Record extends JFrame implements ActionListener int time=0; JTextField yourName,label; JButton confirm,cancel; File gradeFile=null; public Record(File f) super(记录你的成绩到:+f.toString(); gradeFile=f; setBounds(100,100,330,160); setResizable(false); setVisible(false); confirm=new JButton(确定); cancel=new JButton(取消); yourName=new JTextField(8); yourName.setText(匿名); confirm.addActionListener(this); cancel.addActionListener(this); Container con=getContentPane(); con.setLayout(new GridLayout(2,1); label=new JTextField(输入你的姓名,将成绩存放到排行榜:+f.toString(); label.setEditable(false); con.add(label); JPanel p=new JPanel(); p.add(yourName); p.add(confirm); p.add(cancel); con.add(p); addWindowListener(new WindowAdapter() public void windwoClosing(WindowEvent e) setVisible(false); dispose(); ); public void setFile(File f) gradeFile=f; public void setTime(int time) this.time=time; public void actionPerformed(ActionEvent e) if(e.getSource()=confirm) try FileInputStream in=new FileInputStream(gradeFile); ObjectInputStream object_in=new ObjectInputStream(in); LinkedList list=(LinkedList)object_in.readObject(); object_in.close(); in.close(); People people=new People(yourName.getText(),time); list.add(people); FileOutputStream out=new FileOutputStream(gradeFile); ObjectOutputStream object_out=new ObjectOutputStream(out); object_out.writeObject(list); out.close(); object_out.close(); catch(Exception event) System.out.println(event); setVisible(false); dispose(); if(e.getSource()=cancel) setVisible(false); dispose(); 5) 、ShowRecord.javaimport java.io.*;import java.util.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;public class ShowRecord extends JDialog implements ActionListener File gradeFile=null; JButton confirm,clean; JTextArea show=null; public ShowRecord(JFrame frame,File f) super(frame,记忆测试排行榜:+f
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 餐厅年三十活动方案策划(3篇)
- 心理中心活动策划方案范文(3篇)
- 火道墙施工方案(3篇)
- 人工手绘施工方案(3篇)
- 活动方案策划要求怎么写(3篇)
- 元旦口腔门诊活动方案策划(3篇)
- 小区pe井施工方案(3篇)
- 彩钢瓦喷漆防水施工方案(3篇)
- 北京市昌平区2024-2025学年八年级下学期期末质量监测物理题库及答案
- 校测常识题目及答案高一
- 《文献检索与综述实训教程》课件第一章
- 《城市更新的》课件
- 2022水环式机械真空泵选型计算手册
- 2025-2030中国辣椒酱行业供需趋势及投资风险研究报告
- 跨国企业ESG审计实践-全面剖析
- 2025年度运输业安全生产知识竞赛试题(附答案)
- 光伏居间的合同8篇
- 新能源汽车技术试题库(含答案)
- GB/T 45418-2025配电网通用技术导则
- 医疗风险防控培训课件
- 机械设计部绩效考核制度
评论
0/150
提交评论