ImageVerifierCode 换一换
格式:DOCX , 页数:21 ,大小:18.07KB ,
资源ID:26977446      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/26977446.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(记忆测试系统 JAVA实现.docx)为本站会员(b****3)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

记忆测试系统 JAVA实现.docx

1、记忆测试系统 JAVA实现/主类MemoryGameimport javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.LinkedList;public class MemoryGame extends JFrame implements ActionListener JMenuBar bar; JMenu menuGrade,menuResult,menuIcon; JMenuItem oneGradeItem,twoGradeItem,threeGradeItem

2、; JMenuItem oneGradeResult,twoGradeResult,threeGradeResult; JMenuItem carImageIcon,animalImageIcon; File fileOneGrade,fileTwoGrade,fileThreeGrade,gradeFile; String imageName; MemoryTestArea memoryArea; ShowRecordDialog showDiolag=null; int m=5,n=6; final int imageNumber=7; MemoryGame() fileOneGrade=

3、new File(初级记忆排行榜.txt); fileTwoGrade=new File(中级记忆排行榜.txt); fileThreeGrade=new File(高级记忆排行榜.txt); bar=new JMenuBar(); menuGrade=new JMenu(选择级别); oneGradeItem=new JMenuItem(初级); twoGradeItem=new JMenuItem(中级); threeGradeItem=new JMenuItem(高级); menuGrade.add(oneGradeItem); menuGrade.add(twoGradeItem);

4、menuGrade.add(threeGradeItem); menuResult=new JMenu(查看排行榜); oneGradeResult=new JMenuItem(初级排行榜); twoGradeResult=new JMenuItem(中级排行榜); threeGradeResult=new JMenuItem(高级排行榜); menuResult.add(oneGradeResult); menuResult.add(twoGradeResult); menuResult.add(threeGradeResult); menuIcon=new JMenu(选择图标); car

5、ImageIcon=new JMenuItem(汽车图标); animalImageIcon=new JMenuItem(动物图标); animalImageIcon.addActionListener(this); carImageIcon.addActionListener(this); menuIcon.add(carImageIcon); menuIcon.add(animalImageIcon); bar.add(menuGrade); bar.add(menuResult); bar.add(menuIcon); setJMenuBar(bar); oneGradeItem.add

6、ActionListener(this); twoGradeItem.addActionListener(this); threeGradeItem.addActionListener(this); oneGradeResult.addActionListener(this); twoGradeResult.addActionListener(this); threeGradeResult.addActionListener(this); if(!fileOneGrade.exists() try fileOneGrade.createNewFile(); catch(IOException

7、exp) if(!fileTwoGrade.exists() try fileTwoGrade.createNewFile(); catch(IOException exp) if(!fileThreeGrade.exists() try fileThreeGrade.createNewFile(); catch(IOException exp) setBounds(100,100,400,360); setVisible(true); memoryArea=new MemoryTestArea(); imageName=new StringimageNumber; for(int i=0;i

8、imageName.length;i+) imageNamei=new String(car+i+.jpg); m=5; n=6; gradeFile=fileOneGrade; memoryArea.initBlock(m,n,imageName,gradeFile); add(memoryArea,BorderLayout.CENTER); showDiolag=new ShowRecordDialog(); validate(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); public void actionPerformed(Act

9、ionEvent event) if(event.getSource()=oneGradeItem) m=5; n=6; gradeFile=fileOneGrade; memoryArea.initBlock(m,n,imageName,gradeFile); if(event.getSource()=twoGradeItem) m=6; n=7; gradeFile=fileTwoGrade; memoryArea.initBlock(m,n,imageName,gradeFile); if(event.getSource()=threeGradeItem) m=7; n=8; grade

10、File=fileThreeGrade; memoryArea.initBlock(m,n,imageName,gradeFile); if(event.getSource()=carImageIcon) for(int i=0;iimageName.length;i+) imageNamei=new String(car+i+.jpg); memoryArea.setImageName(imageName); memoryArea.initBlock(m,n,imageName,gradeFile); if(event.getSource()=animalImageIcon) for(int

11、 i=0;iimageName.length;i+) imageNamei=new String(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()=twoG

12、radeResult) showDiolag.setGradeFile(fileTwoGrade); showDiolag.showRecord(); showDiolag.setVisible(true); if(event.getSource()=threeGradeResult) showDiolag.setGradeFile(fileThreeGrade); showDiolag.showRecord(); showDiolag.setVisible(true); public static void main(String args) new MemoryGame(); /Memor

13、yTestArea类import javax.swing.*; import java.awt.event.*;import java.awt.*;import java.util.*;import java.io.*;public class MemoryTestArea extends JPanel implements ActionListener,Runnable int row,col; File gradeFile; ArrayList allBlockList; String imageFileName; LinkedList openIconList; LinkedList o

14、penBlockList; int success=0; Thread hintThead; JButton hintButton; int usedTime=0; JTextField showUsedTime,hintMessage; javax.swing.Timer timer; Record record; JPanel center,south; MemoryTestArea() setLayout(new BorderLayout(); allBlockList=new ArrayList(); openIconList=new LinkedList(); openBlockLi

15、st=new LinkedList(); hintThead=new Thread(this); hintMessage=new JTextField(); hintMessage.setHorizontalAlignment(JTextField.CENTER); hintMessage.setEditable(false); hintMessage.setFont(new Font(宋体,Font.BOLD,18); center=new JPanel(); south=new JPanel(); hintButton=new JButton(提示); hintButton.addActi

16、onListener(this); showUsedTime=new JTextField(8); showUsedTime.setEditable(false); showUsedTime.setHorizontalAlignment(JTextField.CENTER); south.add(new JLabel(用时:) ; south.add(showUsedTime); south.add(new JLabel(提示图标位置(导致用时增加):) ; south.add(hintButton); add(south,BorderLayout.SOUTH); add(hintMessag

17、e,BorderLayout.NORTH); timer=new javax.swing.Timer(1000,this); record=new Record(); public void initBlock(int m,int n,String name,File f) row=m; col=n; gradeFile=f; center.removeAll(); imageFileName=name; ImageIcon icon=new ImageIconimageFileName.length; for(int i=0;iicon.length;i+) iconi=new ImageI

18、con(imageFileNamei); if(allBlockList.isEmpty() for(int i=0;irow*col;i+) allBlockList.add(new Block(); else allBlockList.clear(); for(int i=0;irow*col;i+) allBlockList.add(new Block(); for(int i=0;iallBlockList.size();i+) allBlockList.get(i).addActionListener(this); allBlockList.get(i).setOpenStateIc

19、on(iconi%row); Collections.shuffle(allBlockList); center.setLayout(new GridLayout(row,col); for(int i=0;iallBlockList.size();i+) center.add(allBlockList.get(i); add(center,BorderLayout.CENTER); if(timer.isRunning() timer.stop(); hintMessage.setText(您需要用鼠标单击出+col+个同样图标的方块); usedTime=0; showUsedTime.s

20、etText(null); validate(); public void setImageName(String name) imageFileName=name; public void actionPerformed(ActionEvent e) if(e.getSource() instanceof Block) if(!timer.isRunning() timer.start(); Block block=(Block)e.getSource(); ImageIcon openStateIcon=block.getOpenStateIcon(); block.setIcon(ope

21、nStateIcon); if(openIconList.size()=0) openIconList.add(openStateIcon); openBlockList.add(block); success=1; else ImageIcon temp=openIconList.getLast(); if(temp=openStateIcon&!(openBlockList.contains(block) success=success+1; openIconList.add(openStateIcon); openBlockList.add(block); if(success=col)

22、 for(int i=0;iallBlockList.size();i+) allBlockList.get(i).setEnabled(false); for(int j=0;jopenBlockList.size();j+) Block b=openBlockList.get(j); b.setDisabledIcon(b.getOpenStateIcon(); timer.stop(); record.setTime(usedTime); record.setGradeFile(gradeFile); record.setVisible(true); else if(temp!=open

23、StateIcon)&(!(openBlockList.contains(block) openIconList.clear(); openBlockList.clear(); openIconList.add(openStateIcon); openBlockList.add(block); success=1; for(int i=0;iallBlockList.size();i+) if(allBlockList.get(i)!=block) allBlockList.get(i).setIcon(null); if(e.getSource()=hintButton) if(!hintT

24、head.isAlive() hintThead=new Thread(this); for(int i=0;iallBlockList.size();i+) allBlockList.get(i).removeActionListener(this); usedTime=usedTime+10; try hintThead.start(); catch(IllegalThreadStateException ex) if(e.getSource()=timer) usedTime+; showUsedTime.setText(您的用时:+usedTime+秒); public void ru

25、n() for(int i=0;iallBlockList.size();i+) allBlockList.get(i).setIcon(allBlockList.get(i).getOpenStateIcon(); try Thread.sleep(1200); catch(InterruptedException exp) for(int i=0;iallBlockList.size();i+) allBlockList.get(i).addActionListener(this); for(int i=0;iallBlockList.size();i+) if(!openBlockLis

26、t.contains(allBlockList.get(i) allBlockList.get(i).setIcon(null); /Block 类import javax.swing.*;import java.awt.event.*;public class Block extends JButton ImageIcon openStateIcon; public ImageIcon getOpenStateIcon() return openStateIcon; public void setOpenStateIcon(ImageIcon icon) openStateIcon=icon

27、; /Record类import java.io.*;import java.util.*;import javax.swing.*;import java.awt.event.*;import java.awt.*;public class Record extends JDialog implements ActionListener int time=0; JTextField yourName; JLabel label; JButton enter,cancel; File gradeFile=null; public Record() setBounds(100,100,330,1

28、60); setResizable(false); setModal(true); setVisible(false); enter=new JButton(确定); cancel=new JButton(取消); yourName=new JTextField(8); yourName.setText(匿名); enter.addActionListener(this); cancel.addActionListener(this); setLayout(new GridLayout(2,1); label=new JLabel(); add(label); JPanel p=new JPa

29、nel(); p.add(yourName); p.add(enter); p.add(cancel); add(p); public void setGradeFile(File f) gradeFile=f; setTitle(保存成绩到+gradeFile.getName(); label.setText(保存成绩到+gradeFile.getName(); validate(); public void setTime(int time) this.time=time; public void actionPerformed(ActionEvent e) if(e.getSource()=enter) LinkedList list=new LinkedList(); try RandomAccessFile out=new RandomAccessFile(gradeFile,rw

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1