网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > JAVA > 其它技术 > 英文打字练习  

英文打字练习

2003-08-09  作者:BitsCN整理  来源:中国网管联盟  点评 投稿 收藏


  java写的英文打字练习的applet:
  game.java文件:
  -----------------------
  import java.awt.*;
  import java.applet.*;
  import java.io.*;
  import begin;
  
  
  public class game extends Applet{
  String beginLabel=" 开 始 ";
  String quitLabel=" 退 出 ";
  Label label= new Label("B/S英文打字练习1.0版");
  TextArea context= new TextArea(5,50);
  Button beginButton= new Button(beginLabel);
  Button quitButton= new Button(quitLabel);
  begin bb;
  
  
  public void init(){
  context.setText("Welcome to www.chinabs.net for java technicology.");
  setBackground(Color.white);
  Font f=new Font("SansSerif",Font.BOLD,16);
  label.setFont(f);
  add("North",label);
  add("North",context);
  add("South",beginButton);
  add("South",quitButton);
  }
  
  
  public boolean action(Event evt, Object arg){
  if(arg.equals(beginLabel)){ 网管联盟bitsCN@com
  if (bb == null)
  bb=new begin(this,context.getText());
  else
  bb.setText(context.getText());
  bb.show();
  return true;
  }
  else if(arg.equals(quitLabel)){
  System.exit(0);
  return true;
  }
  else
  return false;
  }
  }
  
  
  begin.java文件:
  -----------------------
  import java.applet.*;
  import java.awt.*;
  
  
  class Coordinate{
  public int x,y;
  public char name;
  public TextField tt;
  public Coordinate(int x,int y,char na){
  this.x=x;
  this.y=y;
  name= na;
  }
  }
  
  
  public class begin extends Frame{
  public Applet parent;
  public int wrong=0;
  Coordinate number[];
  char key[];
  char gst[];
  String message= "~1234567890-=``QWERTYUIOP[]&&ASDFGHJKL:"```ZXCVBNM,.?`|` ";
  String message2="~1234567890-=``qwertyuiop[]&&asdfghjkl:"```zxcvbnm,.?`|` ";

网管u家u.bitscn@com


  String gamestring="welcome to my homepage.click any key to begin.";
  String quitlabel="返 回";
  String clearlabel="重新开始";
  public String yourrecord= null;
  int gst_length;
  int message_length;
  public TextField tt;
  public int changei=56;
  public int gstch=1;
  public FontMetrics font_m;
  public int string_x=100;
  public Button clear1,close;
  int w= 0,h=0;
  
  
  public begin(Applet parent,String m){
  super("英文打字练习");
  this.parent= parent;
  this.setBackground(Color.white);
  gamestring= m;
  Panel panel= new Panel();
  tt= new TextField(13);
  clear1= new Button(clearlabel);
  close= new Button(quitlabel);
  add("South",tt);
  panel.setLayout(new FlowLayout());
  panel.add(clear1);
  panel.add(close);
  message_length= message.length();
  key= new char[message_length];
  message.getChars(0,message_length,key,0);
  gst_length= gamestring.length(); 网管联盟bitsCN@com
  gst= new char[gst_length];
  gamestring.getChars(0,gst_length,gst,0);
  init();
  add("North",panel);
  resize(600,450);
  h= 120;
  setResizable(false);
  show();
  }
  
  
  public void setText(String tt){
  gamestring= tt;
  gst_length= gamestring.length();
  gst= new char[gst_length];
  gamestring.getChars(0,gst_length,gst,0);
  gstch=1;
  wrong=0;
  Graphics g= getGraphics();
  string_x=100;
  repaint();
  }
  
  
  public void init(){
  setBackground(Color.white);
  h=450/3;
  number= new Coordinate[message_length+50];
  for(int I=0;I<14;I++){
  number[I]= new Coordinate(62+I*30,h,key[I]);
  }
  for(int I=0;I<14;I++){
  number[14+I]= new Coordinate(64+I*30,h+30,key[14+I]);
  }
  for(int I=0;I<14;I++){
  number[28+I]= new Coordinate(66+I*30,h+60,key[28+I]);
  }
  for(int I=0;I<14;I++){
  number[42+I]= new Coordinate(68+I*30,h+90,key[42+I]); 网管联盟bitsCN@com
  }
  number[56]= new Coordinate(60,130+h,key[56]);
  }
  
  
  public void downboard(int I,Graphics g){
  int index=I;
  if(index!=56){
  g.setColor(Color.lightGray);
  g.fillRect(number[index].x+3,number[index].y+4,23,21);
  for(int i1=0,j=1;i1<3;i1++,j+=2){
  g.setColor(Color.white);
  g.fillRect(number[index].x+28-(i1+1),number[index].y+i1+1,1,28-(2*i1+1)-1);
  g.fillRect(number[index].x+i1,number[index].y+28-(i1+1),28-(2*i1),1);
  g.setColor(Color.gray);
  g.fillRect(number[index].x+i1,number[index].y+i1+1,28-(2*i1),1);
  g.fillRect(number[index].x+i1,number[index].y+i1+1,1,28-(2*i1+1)-1);
  }
  g.setColor(Color.black);
  g.drawChars(key,index,1,number[index].x+12,number[index].y+17);
  }
  else{
  g.setColor(Color.lightGray);
  g.fillRect(number[index].x+53,number[index].y+4,303,21);
  for(int i1=0,j=1;i1<3;i1++,j+=2){
  g.setColor(Color.white);
  g.fillRect(number[index].x+360-(i1+1),number[index].y+i1+1,1,28-(2*i1+1)-1);

网管u家u.bitscn@com


  g.fillRect(number[index].x+i1+50,number[index].y+28-(i1+1),310-(2*i1),1);
  g.setColor(Color.gray);
  g.fillRect(number[index].x+i1+50,number[index].y+i1+1,310-(2*i1),1);
  g.fillRect(number[index].x+i1+50,number[index].y+i1+1,1,28-(2*i1+1)-1);
  }
  }
  }
  
  
  public void paintboard(int I,Graphics g){
  int index=I;
  if(index!=56){
  for(int i1=0,j=1;i1<3;i1++,j+=2){
  g.setColor(Color.gray);
  g.fillRect(number[index].x+28-(i1+1),number[index].y+i1+1,1,28-(2*i1+1)-1);
  g.fillRect(number[index].x+i1,number[index].y+28-(i1+1),28-(2*i1),1);
  g.setColor(Color.white);
  g.fillRect(number[index].x+i1,number[index].y+i1+1,28-(2*i1),1);
  g.fillRect(number[index].x+i1,number[index].y+i1+1,1,28-(2*i1+1)-1);
  }
  g.setColor(Color.black);
  g.drawChars(key,index,1,number[index].x+12,number[index].y+17);
  }
  else{
  for(int i1=0,j=1;i1<3;i1++,j+=2){
  g.setColor(Color.gray);
  g.fillRect(number[index].x+360-(i1+1),number[index].y+i1+1,1,28-(2*i1+1)-1);

中国网管联盟bitsCN.com


  g.fillRect(number[index].x+i1+50,number[index].y+28-(i1+1),310-(2*i1),1);
  g.setColor(Color.white);
  g.fillRect(number[index].x+i1+50,number[index].y+i1+1,310-(2*i1),1);
  g.fillRect(number[index].x+i1+50,number[index].y+i1+1,1,28-(2*i1+1)-1);
  }
  }
  }
  
  
  public void paint(Graphics g){
  g.setColor(Color.lightGray);
  g.fillRect(0,0,600,450);
  for(int I=0;I<=56;I++)
  paintboard(I,g);
  g.drawString(gamestring,string_x,100);
  }
  
  
  int ch = gst[gstch];
  Graphics g1=getGraphics();
  record=message2.indexOf(ch);
  if(record!=56){
  g1.setColor(Color.blue);
  g1.fillRect(number[record].x+3,number[record].y+4,22,21);
  g1.setColor(Color.red);
  g1.drawChars(key,record,1,number[record].x+10,number[record].y+18);
  }
  else{
  g1.setColor(Color.blue);
  g1.fillRect(number[record].x+53,number[record].y+4,303,21);
  }
  }
  
  
  public boolean keyDown(Event evt,int key){ 中国网管论坛bbs.bitsCN.com
  int record2=0;
  Graphics g= getGraphics();
  if(key==8){
  tt.setText("Back Space");
  paintboard(changei,g);
  downboard(13,g);
  changei=13;
  gstch--;
  string_x=string_x-(font_m.charWidth(gst[gstch-1]));
  g.setColor(Color.white);
  g.drawChars(gst,gstch-1,1,string_x,100);
  return true;
  }
  search();
  String aa=Integer.toString(key);
  record2=gamestring.indexOf(key,gstch-1);
  font_m=g.getFontMetrics();
  if(record2==(gstch-1))
  g.setColor(Color.blue);
  else{

TAGs练习   打字   英文   i1   number   index   .x   .y   g.fillRect   g.setColor    
 上一篇:java绘制一个成交量的统计图   下一篇:this关键字
相关文章列表
英文打字练习 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
1.JACOB配置方法及两个常见错误解决
2.用java api进行sort
3.Java中this、super用法简谈
4.Class文件详解 (2)
5.Apache目录服务器中存储Java对象
6.Java 操作二维数组实例
7.Lucene 索引文件格式的规格定义
8.英文打字练习
9.Java如何共享资源
10.editplus能够编译java嘛? 如何设置
最新推荐文章:
1.J2SE实现windows读取网卡的物理地址
2.使用Jetty和DWR创建伸缩性Comet程序
3.经验分享:我的20天项目经历
4.实现Java跨平台运行的十二个注意事项
5.成功的必要条件:开源思想推动创新
6.100行Java代码构建一个线程池
7.用Stripes做Java Web开发
8.j2me创意--Wap浏览器的源代码
9.使用Hashtable对字符串进行碰撞
10.定制 bugzilla 进行项目管理
网管论坛交流:
·不疯魔不成活
·令你大开眼界的真正标准化机房,已整理重
·为赈灾,女孩舍身拍“裸照”
·Windows Server 2003服务器群集创建和配
·exchange2k3全套官方资料
·双儿一周岁了。。。特殊的礼物来啦。。
·存储备份技术版块守则
·无盘技术交流区守则
·DOS命令基础大全之命令详解<作者吐血
·Windows XP 操作系统默认设置需要注意的