How to Add to KeyListener
- 1). Start your .java file with a class that implements the KeyListener interface: "public class tempClass implements KeyListener."
- 2). Create void functions to handle the three main KeyListener methods. You do not have to use all three methods in your class. For example:
"public void keyPressed( keyEvent e)
{
displayKey(e, "You pressed: ");
}" - 3). Retrieve the information about the key that was pressed, typed or released for use in your program logic. For example: "e.getKeyCode();" retrieves the numerical code for the key and "e.getKeyChar();" returns the Unicode value associated with the key. Replace "e" with the variable for your keyEvent.
Source...