打字训练软件Word格式.docx

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

打字训练软件Word格式.docx

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

打字训练软件Word格式.docx

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

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("

jpng);

jpc2.add("

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+"

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("

)){

JOptionPane.showMessageDialog(null,"

请选择文本文档"

"

提示"

JOptionPane.INFORMATION_MESSAGE);

readyFile();

readFile();

state="

addFile"

card1.show(jpc1,"

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,"

jta2.setText(null);

jta2.setEditable(true);

jta2.requestFocus();

state="

start"

lock=false;

startTime=System.currentTimeMillis();

Timerti=newTimer();

Threadt=newThread(ti);

t.start();

else{

请输入数字"

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("

if(fileOver){

state="

over"

}

else{

words+=str2.length();

for(inti=0;

i<

str2.length();

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?

l2-l1:

0,l=l1<

l1:

l2;

for(inti=0;

l;

if(str1.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;

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<

setTime&

!

state.equals("

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("

速度:

putScore();

图3.4速度和剩余时间

3.5显示测试结果

显示录入速度和错误率。

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

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

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

图3.5显示测试结果

4、实验设计总结

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

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

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

附录

组员

任务分配

自评

最后得分

软件测试,撰写文档

85

找相关的资料,调试程序

写代码

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

当前位置:首页 > 初中教育 > 数学

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

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