Design topic
This program is to display the character JTextField object corresponding to the user button to display characters. When you press a certain alphanumeric key, a keyboard event is generated. The keyboard event is handled by the keyTyped method. Before displaying the user button, remove the previous character in the JTYPEFIELD object --- Programs only display only one character at a time, The character corresponds to the button, in the homepage program, the font of the character is set to Chinese_GB2312, the color random change of characters, because the Keylistener interface contains three methods, and only one method of implementation in a program, Use an anonymous mechanism to register a listener object.
Note: When the keyboard occurs, the operation method to be performed is specified below. The Keylistener interface consists of three: keypressed, keyreleased, keytyped.
When a META key (such as Control, Shift, Alt) is pressed, KeyPressed; execute the keytyped when pressing the letter; KEYRELEASED is executed when the selected is released.
Import java.awt. *;
Import java.awt.event. *;
Import javax.swing. *;
Public class onechar extends japplet {
Jtextfield ONELETER = New JtextField (1);
Public void init () {
Container C = getContentPane ();
Onletter.addKeylistener (New KeyAdapter () {
Public void keytyped (KeyEvent E) {
Float Red, Green, Blue;
Color FG, BG;
Onletter.SetText ("");
RED = (float) math.random ();
Green = (float) math.random ();
Blue = (float) math.random ();
FG = New Color (Red, Green, Blue);
BG = color.white;
Onletter.SetForeground (FG);
Onletter.SetBackground (BG);
Onletter.SetCaretcolor (BG);
ONELETTER.SETFONT (New Font ("Courior", Font.Bold, 200);
}
});
C.SetLayout (New GridLayout (1, 1));
C.SetBackground (color.white);
C.ADD (ONELETTER);
JOPTIONPANE.SHOWMESSAGEDIALOG (NULL, "CLINK ON The applet;" information ", JOPANE.PLAIN_MESSAGE
}
}
HTML is described as follows:
Applet> body>
Html> Using the Applet class, you need to define the HTML language