Java KeyListener InterfaceThe Java KeyListener is notified whenever you change the state of key. It is notified against KeyEvent. The KeyListener interface is found in java.awt.event package, and it has three methods. Interface declarationFollowing is the declaration for java.awt.event.KeyListener interface: Methods of KeyListener interfaceThe signature of 3 methods found in KeyListener interface are given below:
Methods inheritedThis interface inherits methods from the following interface:
Java KeyListener ExampleIn the following example, we are implementing the methods of the KeyListener interface. KeyListenerExample.java Output: Java KeyListener Example 2: Count Words & CharactersIn the following example, we are printing the count of words and characters of the string. Here, the string is fetched from the TextArea and uses the KeyReleased() method of KeyListener interface. KeyListenerExample2.java Output:
Next TopicJava WindowListener
|