Recursive Data StructuresTopMore Keyboard Input

More Keyboard Input

The program TextApplet uses a TextArea. It is similar to a TextField except that it includes many lines of text and does NOT generate action events. You can either replace all text in the area using setText or add to the end with append. See the program for details.

Finally, the program KeyDemo demonstrates how to pick up keypresses in a program. [Nothing will show up in this demo on the web because all of the output is through System.out.println.] The KeyListener interface includes three methods, keyPressed, keyTyped, and keyReleased, so all three must be included in any program implementing KeyListener, even if only one of them is needed. The others may be given an empty body.

If you run this program someplace where the output is visible, you will notice some funny behavior. Basically you should only depend on the method keyPressed for extracting info on which key was pressed.


Recursive Data StructuresTopMore Keyboard Input