资源简介
一个java打字程序,里面有源码,有说明,可以如果有安装jdk1.7可以双击run.b at运行typer.jar。
代码片段和文件信息
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.filechooser.FileFilter;
class TyperProgram extends Thread implements ActionListener {
private JPanel jpc1jpc2;
private JMenuItem jmijmiExitjmiAbout;
private JTextField jtf1jtf2;
private JTextArea jta1jta2;
private JButton jb1jb2jbAdd;
private CardLayout card1card2;
private String state=““strTime=““;
private StringBuffer strbFile;
private int wordserrorWords;
private double startTime;
private File getPath;
private BufferedReader buf;
private boolean fileOverlock=true;
private class Timer implements Runnable{
public void putScore(){
jta2.setEditable(false);
String str1str2;int l1l2;
str1=jta1.getText();l1=str1.length();
str2=jta2.getText();l2=str2.length();
double error;
int k=l1 for(int i=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();
}
public void run(){
double nowTimespendTimesetTimespeed=0remainTime;
int countremainMinremainSec;
nowTime=System.currentTimeMillis();
spendTime=(nowTime-startTime)/60000;
setTime=Double.parseDouble(strTime);
while(spendTime 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(Exception e){
e.printStackTrace();
}
nowTime=System.currentTimeMillis();
spendTime=(nowTime-startTime)/60000;
}
jtf1.setText(“速度:“+Math.round(speed)+“字/分“);
putScore();
}
}
public void setWindow(){
Jframe jf=new Jframe(“xxx打字高手“);
Container cont=jf.getContentPane();
cont.setLayout(new BorderLayout());
Font ft=new Font(“新新字体“Font.PLAIN20);
JMenuBar jmb=new JMenuBar();
JMenu jmjmHelp;
jm=new JMenu(“文件“);
jmHelp=new JMenu(“帮助“);
jmi=new JMenuItem(“打开“);jmi.setActionCommand(“打开“);
jmi.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_OInputEvent.CTRL_MASK));
jmiExit= new JMenuItem(“退出“);jmiExit.setActionCommand(“退出“);
jmiAbout=new JMenuItem(“关于“);jmiAbout.setActionCommand(“关于“);
jm.add(jmi);jm.addSeparator();jm.add(jmiExit);
jmHelp.add(jmiAbout);
jmb.add(jm);jmb.add(jmHelp);
jtf1=new JTextField();
jtf1.setFont(ft);
jtf1.setEditable(false);
jtf2=new JTextField();
jtf2.setFont(ft);
jtf2.setEditable(false);
JPanel jptf=new JPanel(new GridLayout(02));
jptf.add(jtf1);jptf.add(jtf2);
cont.add(BorderLayout.NORTHjptf)
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 151 2012-01-02 20:41 ReadMe.txt
文件 104219 2012-01-02 20:25 Typer.jar
文件 9270 2012-01-02 20:30 Typer.java
目录 0 2012-01-22 16:21 files\
文件 799 2011-12-06 16:43 files\互联网.txt
文件 3567 2011-12-06 16:43 files\我的父亲.txt
文件 1811 2011-12-06 16:43 files\拾荒不在.txt
文件 12 2011-12-15 10:25 files\短文.txt
目录 0 2012-01-22 16:21 image\
文件 15264 2011-12-22 17:27 image\chen.png
文件 72871 2011-12-21 08:51 image\keyboard.jpg
文件 19 2011-12-31 12:37 run.bat
评论
共有 条评论