熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> JSP教程 >> 正文

英文打字練習

2022-06-13   來源: JSP教程 

  java寫的英文打字練習的applet
  gamejava文件
  -----------------------
  import javaawt*;
  import javaapplet*;
  import javaio*;
  import begin;
  
  
  public class game extends Applet{
  String beginLabel= 開 始 ;
  String quitLabel= 退 出 ;
  Label label= new Label(B/S英文打字練習);
  TextArea context= new TextArea();
  Button beginButton= new Button(beginLabel);
  Button quitButton= new Button(quitLabel);
  begin bb;
  
  
  public void init(){
  contextsetText(Welcome to for java technicology);
  setBackground(Colorwhite);
  Font f=new Font(SansSerifFontBOLD);
  labelsetFont(f);
  add(Northlabel);
  add(Northcontext);
  add(SouthbeginButton);
  add(SouthquitButton);
  }
  
  
  public boolean action(Event evt Object arg){
  if(argequals(beginLabel)){
  if (bb == null)
  bb=new begin(thiscontextgetText());
  else
  bbsetText(contextgetText());
  bbshow();
  return true;
  }
  else if(argequals(quitLabel)){
  Systemexit();
  return true;
  }
  else
  return false;
  }
  }
  
  
  beginjava文件
  -----------------------
  import javaapplet*;
  import javaawt*;
  
  
  class Coordinate{
  public int xy;
  public char name;
  public TextField tt;
  public Coordinate(int xint ychar na){
  thisx=x;
  thisy=y;
  name= na;
  }
  }
  
  
  public class begin extends Frame{
  public Applet parent;
  public int wrong=;
  Coordinate number[];
  char key[];
  char gst[];
  String message= ~=``QWERTYUIOP[]&&ASDFGHJKL:```ZXCVBNM?`|` ;
  String message=~=``qwertyuiop[]&&asdfghjkl:```zxcvbnm?`|` ;
  String gamestring=welcome to my homepageclick any key to begin;
  String quitlabel=返 回;
  String clearlabel=重新開始;
  public String yourrecord= null;
  int gst_length;
  int message_length;
  public TextField tt;
  public int changei=;
  public int gstch=;
  public FontMetrics font_m;
  public int string_x=;
  public Button clearclose;
  int w= h=;
  
  
  public begin(Applet parentString m){
  super(英文打字練習);
  thisparent= parent;
  thissetBackground(Colorwhite);
  gamestring= m;
  Panel panel= new Panel();
  tt= new TextField();
  clear= new Button(clearlabel);
  close= new Button(quitlabel);
  add(Southtt);
  panelsetLayout(new FlowLayout());
  paneladd(clear);
  paneladd(close);
  message_length= messagelength();
  key= new char[message_length];
  messagegetChars(message_lengthkey);
  gst_length= gamestringlength();
  gst= new char[gst_length];
  gamestringgetChars(gst_lengthgst);
  init();
  add(Northpanel);
  resize();
  h= ;
  setResizable(false);
  show();
  }
  
  
  public void setText(String tt){
  gamestring= tt;
  gst_length= gamestringlength();
  gst= new char[gst_length];
  gamestringgetChars(gst_lengthgst);
  gstch=;
  wrong=;
  Graphics g= getGraphics();
  string_x=;
  repaint();
  }
  
  
  public void init(){
  setBackground(Colorwhite);
  h=/;
  number= new Coordinate[message_length+];
  for(int I=;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{

From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19295.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.