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); }
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]); }