汉字打字练习 - java代码

更新时间:2024-02-27 19:20:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

import java.awt.*;

import java.awt.event.*; public class E10_1{ public static void main(String[] args){ //TODO Auto-generated method stub new MainFrame(); } }

class WordThread extends Thread{ //通过继承Thread类创建线程 char word; int k=19968; Label show; WordThread(Label show){ this.show=show; } public void run(){ //重载run函数 k=19968; while(true){ word=(char)k; show.setText(\ try{sleep(6000);} catch(InterruptedException e){} k++; if(k>=29968)k=19968; } } }

class MainFrame extends Frame implements ActionListener{ Label wordLabel; Button button; TextField inputText,scoreText; WordThread giveWord; int score=0; MainFrame(){ wordLabel=new Label(\ wordLabel.setFont(new Font(\ button=new Button(\开始\

}

inputText=new TextField(3); scoreText=new TextField(5); scoreText.setEditable(false); giveWord=new WordThread(wordLabel); button.addActionListener(this); inputText.addActionListener(this); add(button,BorderLayout.NORTH); add(wordLabel,BorderLayout.CENTER); Panel southPanel=new Panel(); southPanel.add(new Label(\输入标签所显示的汉字,然后回车:\ southPanel.add(inputText); southPanel.add(scoreText); add(southPanel,BorderLayout.SOUTH); setBounds(100,100,350,180); setVisible(true); validate(); addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e) { System.exit(0); } } ); }

public void actionPerformed(ActionEvent e){ if (e.getSource()==button){ if(!(giveWord.isAlive())) { giveWord=new WordThread(wordLabel); } try{ giveWord.start();} catch(Exception exe){} } else if(e.getSource()==inputText){ if(inputText.getText().equals(wordLabel.getText())){ score++; } scoreText.setText(\得分\ inputText.setText(null); } }

本文来源:https://www.bwwdw.com/article/5gqa.html

Top