网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  英文打字练习     
  文章作者:未知  文章来源:水木森林  
  查看:108次  录入:管理员--2007-11-17  
 
  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)){
  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,.?`|` ";
  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();
  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]);
  }
  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);
  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);
  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){
  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{
 
 
上一篇: java绘制一个成交量的统计图    下一篇: this关键字
  相关文档
封装jndi操作ldap服务器的工具类(1) 11-17
在 was 中使用 java 安全套接字扩展(图) 11-17
使用技巧:通过java.net包建立双向通讯 11-16
第十三讲:关于.net组件 11-17
maven 安装实践 11-17
《学不会的java,消不了的忧愁》之五——献给那些酷爱计算机编.. 11-17
java无线开发教程之一 11-16
详解java中的指针、引用及对象的clone 11-17
j2me编程最佳实践之屏幕导航 11-16
sql&loader可把文件中的数据装载到or 11-17
jive论坛与spring框架 11-17
关于jcreator pro 3.0的一个折中处理方案(序列号和汉字)(转) 11-17
jagilesearch 1.0 alpha done 11-17
超越梦想 ejb 3.0 规范全新体验 11-17
j2se综合--有关 java 的多线程浅析 02-03
java入门教程:java概述 11-17
java数据库编程中查询结果的输出 11-17
在java中动态执行类的静态方法 11-17
四种java脚本语言的评测 11-17
面向对象编程:java中的抽象数据类型 11-16
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
厦门(总部):13616026886 福州:0591-87655121
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息