Table of Contents
Java Event Classes
The literal term of the word ‘event’ signifies a particular action that triggers some response. Such an action brings about a change in the current scenario of things. In Java as well, an event is defined as the process which brings about a change in the state of an object. Some of the most common events in Java are clicking of a button or dragging the mouse cursor to perform some action. Every event is thereafter followed by a Listener interface which performs an action in response to the event. The java.awt.event package provides several event classes and listener interfaces that can be used to perform event handling.
Java Event Classes and Listener Interfaces
Event Classes | Listener Interfaces |
ActionEvent | ActionListener |
MouseEvent | MouseListener and MouseMotionListener |
MouseWheelEvent | MouseWheelListener |
KeyEvent | KeyListener |
ItemEvent | ItemListener |
TextEvent | TextListener |
AdjustmentEvent | AdjustmentListener |
WindowEvent | WindowListener |
ComponentEvent | ComponentListener |
ContainerEvent | ContainerListener |
FocusEvent | FocusListener |
Steps to Perform Event Handling
To be able to handle a Java event successfully, the following step have to be carried out:
The primary requirement is to register the event component of your code with a Listener such that your program knows how to respond to an event.
Registration Methods
- Button – public void addActionListener (ActionListener a) {}
- MenuItem – public void addActionListener (ActionListener a) {}
- TextField – public void addActionListener (ActionListener a) {}
- TextField – public void addTextListener (TextListener a) {}
- TextArea – public void addTextListener (TextListener a) {}
- Checkbox – public void addItemListener (ItemListener a) {}
- Choice – public void addItemListener (ItemListener a) {}
- List – public void addActionListener (ActionListener a) {}
- List – public void addItemListener (ItemListener a) {}
0 Comments