课程设计名称Java课程设计.docx
- 文档编号:10960508
- 上传时间:2023-02-24
- 格式:DOCX
- 页数:47
- 大小:134.58KB
课程设计名称Java课程设计.docx
《课程设计名称Java课程设计.docx》由会员分享,可在线阅读,更多相关《课程设计名称Java课程设计.docx(47页珍藏版)》请在冰豆网上搜索。
课程设计名称Java课程设计
课程设计名称:
Java课程设计
设计题目:
记忆测试系统
设计依据、要求及主要内容(可另加附页):
任务:
记忆测试系统是通过回忆法测试记忆能力,测试手段分为初级、中级和高级三个级别。
功能要求:
(1)单击“选择级别”菜单可以选择初级、中级和高级。
(2)单击“查看排行榜”菜单可以查看初级记忆榜、中级记忆榜或高级记忆榜,通过记忆榜存储每个级别的成绩。
(3)选择级别后,将出现相应级别的测试区。
测试区由m*n个方块组成,程序通过设置m和n的值来确定相应的测试级别,例如,对于初级级别,m=5,n=6.每个方块上都有一个图标,但该图标默认不可见。
用鼠标单击测试区中的任何一个方块,则计时器开始启动,同时该方块上的图标将显示出来。
(4)m*n个方块组成的测试区中有m个图标,每个图标重复出现n次,并且随机分布在测试区中的m*n个方块上。
用户必须用鼠标连续单击出n个图标相同的方块,也就是说,如果用户已经用鼠标连续单击出p(p (5)测试区能显示用户的用时,并根据级别的不同,提示用户必须用鼠标连续单击出多少个图标相同的方块。 (6)测试区有提示图标所在位置的功能。 用户单机测试区中的“提示”按钮后,测试区将持续1.2秒为用户显示全部方块上的图标。 用户每单击一次“提示”按钮,用户的用时将增加10秒。 (7)连续单击出级别所要求的若干个图标形同的方块后,将弹出保存成绩对话框,用户可以通过选择是否将自己的成绩保存到成绩表中。 (8)单击“选择图标”菜单可重新选择方块的图标样式,即可以重新选择m个图标。 指导教师(签字): 教研室主任(签字): 批准日期: 年月日 摘 要 该课程设计主要是设计一个简单的记忆测试系统,主要功能是: 不但可以娱乐;而且可以提高记忆力;系统测试手段分为初级、中级和高级三个级别,并且在此课程设计中采用一定的java语言相应的知识。 这样让我们对java语言和其运行环境等课程有了更深的了解。 关键词: java语言;类;包;对象 目 录 一课题描述…………………………………………………………………………………………………3 二设计过程……………………………………………………………………………………………3-16 2.1MemoryGame类…………………………………………………………………4-7 2.2MemoryTestArea类……………………………………………………………7-10 2.3Block类……………………………………………………………………10-11 2.4Record类……………………………………………………………………11-12 2.5ShowRecordDialog类………………………………………………………12-14 2.6People类……………………………………………………………………………14-16 三测试………………………………………………………………………………………………16 总结………………………………………………………………………………………………17 参考文献…………………………………………………………………………………………17 附录一: 原程序代码……………………………………………………………………18-38 一 课题描述 本课题主要实现一个简单的记忆测试系统,主要功能是: 不但可以娱乐;而且可以提高记忆力;系统测试手段分为初级、中级和高级三个级别。 开发工具: java。 二 设计过程 本次设计主要是在win32 控制台下实现,所以设计的界面比较简单主要以文本串的形式显示给用户.本设计主要有以下几大功能模块: MemoryGame类,MemoryTestArea类,Block类,Record类,ShowRecordDialog类,People类。 流程图: 2.1主程序设计. 如图.主要通过MemoryGame类实现. 如图2-1所示: 图2-1 importjavax.swing.*; importjava.awt.*; importjava.awt.event.*; importjava.io.*; importjava.util.LinkedList; publicclassMemoryGameextendsJFrameimplementsActionListener{ JMenuBarbar; JMenumenuGrade,menuResult,menuIcon; JMenuItemoneGradeItem,twoGradeItem,threeGradeItem; JMenuItemoneGradeResult,twoGradeResult,threeGradeResult; JMenuItemcarImageIcon,animalImageIcon; FilefileOneGrade,fileTwoGrade,fileThreeGrade,gradeFile; StringimageName[]; MemoryTestAreamemoryArea; ShowRecordDialogshowDiolag=null; intm=10,n=8; finalintimageNumber=11; MemoryGame(){ fileOneGrade=newFile("初级记忆排行榜.txt"); fileTwoGrade=newFile("中级记忆排行榜.txt"); fileThreeGrade=newFile("高级记忆排行榜.txt"); bar=newJMenuBar(); menuGrade=newJMenu("选择级别"); oneGradeItem=newJMenuItem("初级"); twoGradeItem=newJMenuItem("中级"); threeGradeItem=newJMenuItem("高级"); menuGrade.add(oneGradeItem); menuGrade.add(twoGradeItem); menuGrade.add(threeGradeItem); menuResult=newJMenu("查看排行榜"); oneGradeResult=newJMenuItem("初级排行榜"); twoGradeResult=newJMenuItem("中级排行榜"); threeGradeResult=newJMenuItem("高级排行榜"); menuResult.add(oneGradeResult); menuResult.add(twoGradeResult); menuResult.add(threeGradeResult); menuIcon=newJMenu("选择图标"); carImageIcon=newJMenuItem("鲜花图标"); animalImageIcon=newJMenuItem("动物图标"); animalImageIcon.addActionListener(this); carImageIcon.addActionListener(this); menuIcon.add(carImageIcon); menuIcon.add(animalImageIcon); bar.add(menuGrade); bar.add(menuResult); bar.add(menuIcon); setJMenuBar(bar); oneGradeItem.addActionListener(this); twoGradeItem.addActionListener(this); threeGradeItem.addActionListener(this); oneGradeResult.addActionListener(this); twoGradeResult.addActionListener(this); threeGradeResult.addActionListener(this); if(! fileOneGrade.exists()){ try{fileOneGrade.createNewFile(); } catch(IOExceptionexp){} } if(! fileTwoGrade.exists()){ try{fileTwoGrade.createNewFile(); } catch(IOExceptionexp){} } if(! fileThreeGrade.exists()){ try{fileThreeGrade.createNewFile(); } catch(IOExceptionexp){} } setBounds(900,100,800,800); setVisible(true); memoryArea=newMemoryTestArea(); imageName=newString[imageNumber]; for(inti=0;i imageName[i]=newString("flo"+i+".jpg"); } m=10; n=8; gradeFile=fileOneGrade; memoryArea.initBlock(m,n,imageName,gradeFile); add(memoryArea,BorderLayout.CENTER); showDiolag=newShowRecordDialog(); validate(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } publicvoidactionPerformed(ActionEventevent){ if(event.getSource()==oneGradeItem){ m=10; n=8; gradeFile=fileOneGrade; memoryArea.initBlock(m,n,imageName,gradeFile); } if(event.getSource()==twoGradeItem){ m=6; n=9; gradeFile=fileTwoGrade; memoryArea.initBlock(m,n,imageName,gradeFile); } if(event.getSource()==threeGradeItem){ m=7; n=10; gradeFile=fileThreeGrade; memoryArea.initBlock(m,n,imageName,gradeFile); } if(event.getSource()==carImageIcon){ for(inti=0;i imageName[i]=newString("flo"+i+".jpg"); } memoryArea.setImageName(imageName); memoryArea.initBlock(m,n,imageName,gradeFile); } if(event.getSource()==animalImageIcon){ for(inti=0;i imageName[i]=newString("ani"+i+".jpg"); } memoryArea.setImageName(imageName); memoryArea.initBlock(m,n,imageName,gradeFile); } if(event.getSource()==oneGradeResult){ showDiolag.setGradeFile(fileOneGrade); showDiolag.showRecord(); showDiolag.setVisible(true); } if(event.getSource()==twoGradeResult){ showDiolag.setGradeFile(fileTwoGrade); showDiolag.showRecord(); showDiolag.setVisible(true); } if(event.getSource()==threeGradeResult){ showDiolag.setGradeFile(fileThreeGrade); showDiolag.showRecord(); showDiolag.setVisible(true); } } publicstaticvoidmain(Stringargs[]){ newMemoryGame(); } } 2.2 MemoryTestArea类 相关实现如下: 图2-2 importjavax.swing.*; importjava.awt.event.*; importjava.awt.*; importjava.util.*; importjava.io.*; import.*; importjava.applet.*; publicclassMemoryTestAreaextendsJPanelimplementsActionListener,Runnable{ introw,col; FilegradeFile; ArrayList StringimageFileName[]; LinkedList LinkedList intsuccess=0; ThreadhintThead; JButtonhintButton; intusedTime=0; JTextFieldshowUsedTime,hintMessage; javax.swing.Timertimer; Recordrecord; JPanelcenter,south; MemoryTestArea(){ setLayout(newBorderLayout()); allBlockList=newArrayList openIconList=newLinkedList openBlockList=newLinkedList hintThead=newThread(this); hintMessage=newJTextField(); hintMessage.setHorizontalAlignment(JTextField.CENTER); hintMessage.setEditable(false); hintMessage.setFont(newFont("宋体",Font.BOLD,18)); center=newJPanel(); south=newJPanel(); hintButton=newJButton("提示"); hintButton.addActionListener(this); showUsedTime=newJTextField(8); showUsedTime.setEditable(false); showUsedTime.setHorizontalAlignment(JTextField.CENTER); south.add(newJLabel("用时: ")); south.add(showUsedTime); south.add(newJLabel("提示图标位置(导致用时增加): ")); south.add(hintButton); add(south,BorderLayout.SOUTH); add(hintMessage,BorderLayout.NORTH); timer=newjavax.swing.Timer(1000,this); record=newRecord(); } publicvoidinitBlock(intm,intn,Stringname[],Filef){ row=m; col=n; gradeFile=f; center.removeAll(); imageFileName=name; ImageIconicon[]=newImageIcon[imageFileName.length]; for(inti=0;i icon[i]=newImageIcon(imageFileName[i]); } if(allBlockList.isEmpty()){ for(inti=0;i allBlockList.add(newBlock()); } } else{ allBlockList.clear(); for(inti=0;i allBlockList.add(newBlock()); } } for(inti=0;i allBlockList.get(i).addActionListener(this); allBlockList.get(i).setOpenStateIcon(icon[i%row]); } Collections.shuffle(allBlockList); center.setLayout(newGridLayout(row,col)); for(inti=0;i center.add(allBlockList.get(i)); } add(center,BorderLayout.CENTER); if(timer.isRunning()){ timer.stop(); } hintMessage.setText("您需要用鼠标单击出"+col+"个同样图标的方块"); usedTime=0; showUsedTime.setText(null); validate(); } publicvoidsetImageName(Stringname[]){ imageFileName=name; } publicvoidactionPerformed(ActionEvente){ if(e.getSource()instanceofBlock){ if(! timer.isRunning()) timer.start(); Blockblock=(Block)e.getSource(); ImageIconopenStateIcon=block.getOpenStateIcon(); block.setIcon(openStateIcon); if(openIconList.size()==0){ openIconList.add(openStateIcon); openBlockList.add(block); success=1; } else{ ImageIcontemp=openIconList.getLast(); if(temp==openStateIcon&&! (openBlockList.contains(block))){ success=success+1; openIconList.add(openStateIcon); openBlockList.add(block); if(success==col){ for(inti=0;i allBlockList.get(i).setEnabled(false); } for(intj=0;j Blockb=openBlockList.get(j); b.setDisabledIcon(b.getOpenStateIcon()); } timer.stop(); record.setTime(usedTime); record.setGradeFile(gradeFile); record.setVisible(true); } } elseif((temp! =openStateIcon)&&(! (openBlockList.contains(block)))){ openIconList.clear(); openBlockList.clear(); openIconList.add(openStateIcon); openBlockList.add(block); success=1; for(inti=0;i if(allBlockList.get(i)! =block) allBlockList.get(i).setIcon(null); FilemusicFile=newFile("1.au");//加音乐 URIuri=musicFile.toURI(); URLurl=uri.toURL(); AudioClipclip=Applet.newAudioClip(url); clip.play(); clip.loop(); clip.stop(); } }
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 课程设计 名称 Java