Applets that can get key values

Source: Internet
Author: User
Tags html page

//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
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.