Abstract Interface KeyListener in java

KeyListener interface defines the methods that an object must implement to “listen” for key events on AWT components. When a KeyEvent occurs, an AWT component notifies its registered KeyListener objects by invoking one of their methods.
An easy way to implement this interface is by subclassing the KeyAdapter class.

Objects that implement the KeyListener interface can receive KeyEvent objects. Listeners must first register themselves with objects that produce events. When events occur, they are then automatically propagated to all registered listeners.

public abstract interface java.awt.event.KeyListener extends java.util.EventListener{
// Public Instance Methods
public abstract void keyPressed(KeyEvent e);
public abstract void keyReleased(KeyEvent e);
public abstract void keyTyped(KeyEvent e);
}

The details of the class structure are given as follows:

public abstract void keyPressed(KeyEvent e);

public abstract void keyPressed(KeyEvent e) method notifies the KeyListener that a key was pressed.

Parameter
e – The key event that occurred.

public abstract void keyReleased(KeyEvent e);

public abstract void keyReleased(KeyEvent e) method notifies the KeyListener that a key was released.

Parameter
e – The key event that occurred.

public abstract void keyTyped(KeyEvent e);

public abstract void keyTyped(KeyEvent e) method notifies the KeyListener that a key was typed (pressed and released).

Parameter
e – The key event that occurred.

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on [email protected]

Write A Comment