//jdk1.3
//<applet code=keyvalue width=100 height=50></applet>
//The applet program is added to the HTML page , and after adding the previous row in the Java source program, you can
//To view the results at the command line by entering Appletviewer Keyvalue.java.
Import java.awt.*;
Import java.awt.event.*;
Import java.applet.*;
public class Main extends Applet implements KeyListener {//define interface type is KeyListener
TextField txt=new TextField (a); label Lab=new label ("keyboard corresponds to ASCII code"); Enter corresponds to the
//button btn=new button ("Excu");
public void init () {//Initialize
Add (TXT);
Add (Lab);
//add (b TN);
Txt.addkeylistener (this);//Add Listener event
}
public void keypressed (KeyEvent e) {//define method
Char CH=E.GETKEYC when keyboard is pressed Har ();
int i= (int) ch;
String s=integer.tostring (i);
Lab.settext (s);
Txt.settext ("");
Txt.requestfocus ();
}
public void keytyped (KeyEvent e) {//define keytyped method
/*char Ch=e.getkeychar ();
int i= (int) ch;
if (i==1 0) {
Lab.settext (Txt.gettext ());
Txt.settext ("");
Txt.requestfocus ();
}*/
}
public void keyreleased (KeyEvent e) {}//define method for keyboard release
}