打字训练软件.docx

上传人:b****5 文档编号:7471951 上传时间:2023-01-24 格式:DOCX 页数:16 大小:527.62KB
下载 相关 举报
打字训练软件.docx_第1页
第1页 / 共16页
打字训练软件.docx_第2页
第2页 / 共16页
打字训练软件.docx_第3页
第3页 / 共16页
打字训练软件.docx_第4页
第4页 / 共16页
打字训练软件.docx_第5页
第5页 / 共16页
点击查看更多>>
下载资源
资源描述

打字训练软件.docx

《打字训练软件.docx》由会员分享,可在线阅读,更多相关《打字训练软件.docx(16页珍藏版)》请在冰豆网上搜索。

打字训练软件.docx

打字训练软件

打字训练软件

 

《Java语言程序设计》课程设计

课设题目:

打字训练测试软件

院系:

计算机科学与技术学院

专业:

物联网

学生姓名:

宋杰

学号:

123921041

学生姓名:

王鹏

学号:

123921042

学生姓名:

于渊

学号:

123921043

指导教师:

段善荣

 

2014年12月

打字训练测试软件

1、打字训练测试软件的概述

1.1背景与意义

计算机在20世纪后半期取得了飞速发展,随着网络的发展,已经成为人们日常生活中不可或缺的一部分,如何快速的掌握计算机操作技能显得非常重要,其中打字速度更是衡量一个人操作熟练与否的重要标志,因此开发一种高效的打字程序显得迫在眉睫。

目前大多数打字程序都是只能在Windows下运行,跨平台运行能力不是很强。

为了适应当下的需求,格外需要一款新的打字程序。

我们小组开发的这个用JAVA设计的打字训练测试软件,它的主要功能是从文件中录入一段英文或中文文档,并能给出错误率和平均录入速度。

在该文档设计中,为了方便,文档格式设置为txt格式。

该软件能实现从磁盘上寻找打开一个文件、实时显示打字速度和剩余时间等功能,应用到GUI,多线程,文件的输入输出等知识。

需要从磁盘打开要录入文件的样本,录入时需要实时显示录入速度和剩余时间,录入结束后,显示录入速度和错误率。

录入结束方式可以通过点击“结束测试”按钮结束测试,文章录入完成也自动结束录入,到达设置时间也自动结束录入。

最后要求图形界面,界面良好美观,主要是为了锻炼一下打字技能,提高打字速度,并能给出错误分析。

2、打字训练测试软件的设计思路

2.1系统主要功能

本程序必需主要实现的功能如下:

1)添加文件。

从磁盘添加现有的文本文件显示在程序界面上方。

2)设置测试时间。

在打字开始前,可以设置测试时间,方便快捷地结束测试。

3)显示测试结果。

结果主要包括:

打字速度和错误率。

4)在录入过程中,显示当前速度和剩余时间。

为了实时提醒用户打字速度和打字时间可以实时提示打字速度和剩余时间(剩余时间是设置的测试时间减掉已使用的时间).

5)使用菜单栏。

要求菜单栏可以从“文件——>打开”添加文件,可以从“文件——>退出”退出程序,可以从“帮助——>关于”了解程序信息。

6)多情况结束测试。

1.当测试结束时,结束测试。

2.当点击“结束测试”按钮结束测试。

3.当文章录入完成结束测试。

2.2系统主要流程图

3、打字训练测试软件的功能模块

3.1主窗口界面设计

窗口为一个添加菜单栏的JFrame,菜单栏包括主要有文件和帮助两个部分,整体的JFrame用BorderLayout进行布局分成北中南三个块。

其中北边是一个用GridLayout布局的JPanel分成0行2列,两列分别是一个JTextField(当前的速度,剩余时间);中间是一个GridLayout布局的JPanel分成2行1列,每行分别为一个CardLayout布局的JPanel,其中第一行里放了一个带按钮的JPanel(添加文件)和一个JTextArea,第二行为JTextArea;南边是一个FlowLayout布局的JPanel,里面放两个居中的按钮(开始测试,结束测试),相关代码如下,该界面如图3.1所示

publicvoidsetWindow(){

JFramejf=newJFrame("英文打字测试");

Containercont=jf.getContentPane();

cont.setLayout(newBorderLayout());

Fontft=newFont("新新字体",Font.PLAIN,20);

JMenuBarjmb=newJMenuBar();

JMenujm,jmHelp;

jm=newJMenu("文件");

jmHelp=newJMenu("帮助");

jmi=newJMenuItem("打开");jmi.setActionCommand("打开");

jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));

jmiExit=newJMenuItem("退出");jmiExit.setActionCommand("退出");

jmiAbout=newJMenuItem("关于");jmiAbout.setActionCommand("关于");

jm.add(jmi);jm.addSeparator();jm.add(jmiExit);

jmHelp.add(jmiAbout);

jmb.add(jm);jmb.add(jmHelp);

jtf1=newJTextField();

jtf1.setFont(ft);

jtf1.setEditable(false);

jtf2=newJTextField();

jtf2.setFont(ft);

jtf2.setEditable(false);

JPaneljptf=newJPanel(newGridLayout(0,2));

jptf.add(jtf1);jptf.add(jtf2);

cont.add(BorderLayout.NORTH,jptf);

JPaneljpg,jpf,jpb;

jpg=newJPanel();

jpg.setLayout(newGridLayout(2,0,0,30));

jta1=newJTextArea();

jta2=newJTextArea(){

privatestaticfinallongserialVersionUID=1L;

@Overridepublicvoidpaste(){}

};

jta1.setFont(ft);

jta1.setLineWrap(true);

jta1.setEditable(false);

jta1.setBackground(newColor(200,255,200));

jta2.setFont(ft);

jta2.setLineWrap(true);

jta2.setEditable(false);

jta2.setBackground(newColor(200,200,255));

jbAdd=newJButton("添加文件");jbAdd.setActionCommand("打开");

jpb=newJPanel(newCardLayout(350,100));

jpb.add("card",jbAdd);

card1=newCardLayout();

jpc1=newJPanel(card1);

jpc1.add("card1",jpb);jpc1.add("card2",jta1);

JLabeljpng=newJLabel(newImageIcon("image/keyboard.jpg"));

card2=newCardLayout();

jpc2=newJPanel(card2);

jpc2.add("card1",jpng);jpc2.add("card2",jta2);

jpg.add(jpc1);jpg.add(jpc2);

cont.add(BorderLayout.CENTER,jpg);

jpf=newJPanel();

jpf.setLayout(newFlowLayout(FlowLayout.CENTER,50,0));

jb1=newJButton("开始测试");jb1.setActionCommand("开始");

jb2=newJButton("结束测试");jb2.setActionCommand("结束");

jpf.add(jb1);jpf.add(jb2);

cont.add(BorderLayout.SOUTH,jpf);

jf.setBounds(250,50,810,630);

Toolkittoolkit=jf.getToolkit();

Imageimage=toolkit.getImage("image/chen.png");

jf.setIconImage(image);

jf.setJMenuBar(jmb);

jf.setVisible(true);jbAdd.requestFocus();

jf.setResizable(false);

jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

图3.1起始界面设计

3.2添加文件功能实现

添加打开文件用打开对话框,并对对话框添加文件过滤器,代码如下,界面如图3.2所示

publicvoidreadFile(){

StringstrPart="";intn=320;

if(strbFile.length()<=n){

jta1.setText(strbFile+"\n");

fileOver=true;

return;

}

strPart=strbFile.substring(0,n);

strbFile=strbFile.delete(0,n);

jta1.setText(strPart+"\n");

}

publicvoidaddFile(){

JFileChooserfileCh=newJFileChooser();

fileCh.setCurrentDirectory(newFile("files"));

fileCh.setFileFilter(newFileFilter(){

publicbooleanaccept(Filef){

returnf.getName().toLowerCase().endsWith(".txt")||f.isDirectory();

}

publicStringgetDescription(){

return"文本文档*.txt*";

}

});

if(fileCh.showOpenDialog(null)==JFileChooser.CANCEL_OPTION)return;

getPath=fileCh.getSelectedFile();

if(!

getPath.getPath().toLowerCase().endsWith(".txt")){

JOptionPane.showMessageDialog(null,"请选择文本文档","提示",JOptionPane.INFORMATION_MESSAGE);

return;

}

readyFile();

readFile();

state="addFile";

card1.show(jpc1,"card2");

jb1.requestFocus();

}

图3.2添加文件界面设计

3.3设置测试时间设计

录入时间设定用一个对话框实现,并接收输入信息,默认录入测试时间为5分钟,主要代码如下该界面如图3.3所示

publicvoidsetstart(){

JPaneljp=newJPanel(newGridLayout(2,0));

JLabeljlab=newJLabel("设置测试时间(分):

");

JTextFieldjtfTime=newJTextField();

jtfTime.setText("5");

jp.add(jlab);jp.add(jtfTime);

intselect=JOptionPane.showConfirmDialog(null,jp,"设置",JOptionPane.OK_CANCEL_OPTION,JOptionPane.PLAIN_MESSAGE);

if(select!

=JOptionPane.OK_OPTION)return;

strTime=jtfTime.getText();

if(isDigit(strTime)){

if(jta1.getText()!

=null){

readyFile();

readFile();

}

card2.show(jpc2,"card2");

jta2.setText(null);

jta2.setEditable(true);

jta2.requestFocus();

state="start";

lock=false;

startTime=System.currentTimeMillis();

Timerti=newTimer();

Threadt=newThread(ti);

t.start();

}

else{

JOptionPane.showMessageDialog(null,"请输入数字","提示",JOptionPane.INFORMATION_MESSAGE);

}

}

publicvoidsetListener(){

jmi.addActionListener(this);

jmiExit.addActionListener(this);

jmiAbout.addActionListener(this);

jbAdd.addActionListener(this);

jb1.addActionListener(this);

jb2.addActionListener(this);

jbAdd.addKeyListener(newKeyListener(){

publicvoidkeyPressed(KeyEvente1){

if(e1.getKeyCode()==KeyEvent.VK_ENTER)

addFile();

}

publicvoidkeyReleased(KeyEvente2){}

publicvoidkeyTyped(KeyEvente2){}

});

jta2.getDocument().addDocumentListener(newDocumentListener(){

publicvoidinsertUpdate(DocumentEvente1){

Stringstr1=jta1.getText();

Stringstr2=jta2.getText();

if(str1.length()==str2.length()&&str2.endsWith("\n")){

if(fileOver){

state="over";

}

else{

words+=str2.length();

for(inti=0;i

if(str1.charAt(i)!

=str2.charAt(i))

errorWords++;

EventQueue.invokeLater(newRunnable(){

publicvoidrun(){

jta2.setText(null);

}

});

readFile();

}

}

}

publicvoidchangedUpdate(DocumentEvente2){}

publicvoidremoveUpdate(DocumentEvente3){}

});

}

图3.3设置测试时间

3.4速度和剩余时间设计

实时显示录入速度和剩余时间通过实现Runnable接口的一个Timer类来计算实现。

当开始录入时获取一个系统时间startTime=System.currentTimeMillis(),然后每隔一秒获取一个系统时间nowTime=System.currentTimeMillis(),同时统计当前录入的字数count=jta2.getText().length(),字数除以用两个时间之差得到速度最后单位换算为(字/分);剩余时间等于设置时间减去花费的时间remainTime=setTime-spendTime最后转换为分和秒,代码如下。

privateclassTimerimplementsRunnable{

publicvoidputScore(){

jta2.setEditable(false);

Stringstr1,str2;intl1,l2;

str1=jta1.getText();l1=str1.length();

str2=jta2.getText();l2=str2.length();

doubleerror;

intk=l1

l2-l1:

0,l=l1

l1:

l2;

for(inti=0;i

if(str1.charAt(i)!

=str2.charAt(i))

k++;

error=(words+l)==0?

0:

((errorWords+k)*1.0/(words+l))*100;

jtf2.setText("错误率:

"+Math.ceil(error*100)/100.0+"%");

errorWords=0;words=0;

state="addFile";lock=true;

jb1.requestFocus();

}

publicvoidrun(){

doublenowTime,spendTime,setTime,speed=0,remainTime;

intcount,remainMin,remainSec;

nowTime=System.currentTimeMillis();

spendTime=(nowTime-startTime)/60000;

setTime=Double.parseDouble(strTime);

while(spendTime

state.equals("over")){

count=jta2.getText().length();

speed=(words+count)/spendTime;

remainTime=setTime-spendTime;

remainMin=(int)remainTime;

remainSec=(int)Math.round((remainTime-remainMin)*60);

jtf1.setText("当前的速度:

"+Math.round(speed)+"字/分");

jtf2.setText("剩余时间:

"+remainMin+"分"+remainSec+"秒");

try{

Thread.sleep(1000);

}catch(Exceptione){

e.printStackTrace();

}

nowTime=System.currentTimeMillis();

spendTime=(nowTime-startTime)/60000;

}

jtf1.setText("速度:

"+Math.round(speed)+"字/分");

putScore();

}

}

图3.4速度和剩余时间

3.5显示测试结果

显示录入速度和错误率。

录入速度计算同上,错误率等于总的错字数/录入总字数error=(words+l)==0?

0:

((errorWords+k)*1.0/(words+l))*100(注:

如果没有录入就结束测试,错误率为0%),界面如图3.5所示

图3.5显示测试结果

4、实验设计总结

经过几个星期,我们的课程设计总算完成了,这其中虽然遇到不少问题,通过询问同学的帮助也一一解决了,通过这次课程设计,使大家的编程能力都提高了不少,这次课程设计给大家提供了一个动手,思考和解决问题的机会,巩固了所学的课程。

在设计中,大家难免会遇到多种分歧,比如在布局管理器上就要想到怎样放置整个组件,使整个界面美观,简单。

总之,这次课程设计是由大家一起完成的,本人也体会到了团队合作的氛围,哪方面不懂的大家都可以一起解决,分享自己的编程心得,最终达到学习的目的。

附录

组员

任务分配

自评

最后得分

宋杰

软件测试,撰写文档

85

王鹏

找相关的资料,调试程序

85

于渊

写代码

85

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

当前位置:首页 > 农林牧渔 > 林学

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

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