An event is one of the most important concepts in Java. The change in the state of an object or behavior by performing actions is referred to as an Event in Java. Actions include button click, keypress, page scrolling, or cursor movement.
Some of the most used Event classes are:
Event Class |
Listener Interface |
Methods |
Descriptions |
|
1. |
ActionEvent |
ActionListener |
actionPerformed() |
ActionEvent
indicates that a component-defined action occurred. |
2. |
AdjustmentEvent |
AdjustmentListener |
adjustmentValueChanged() |
Adjustment events
occur by an adjustable object like a scrollbar. |
3. |
ComponentEvent |
ComponentListener |
componentResized(),
componentMoved(), componentShown() and componentHidden() |
An event occurs when
a component moved, changed its visibility or the size changed. |
4. |
ContainerEvent |
ContainerListener |
componentRemoved()
and componentAdded() |
The event is fired
when a component is added or removed from a container. |
5. |
FocusEvent |
FocusListener |
focusLost() and focusGained() |
Focus events include
focus, focusout, focusin, and blur. |
6. |
ItemEvent |
ItemListener |
itemStateChanged() |
Item event occurs
when an item is selected. |
7. |
KeyEvent |
KeyListener |
keyPressed(),
keyReleased(), and keyTyped(). |
A key event occurs
when the user presses a key on the keyboard. |
8. |
MouseEvent |
MouseListener and
MouseMotionListener |
mouseClicked(),
mousePressed(), mouseEntered(), mouseExited() and mouseReleased() are the mouseListener methods. mouseDregged() and mouseMoved() are the MouseMotionListener() methods. |
A mouse event occurs
when the user interacts with the mouse. |
9. |
MouseWheelEvent |
MouseWheelListener |
mouseWheelMoved(). |
MouseWheelEvent
occurs when the mouse wheel rotates in a component. |
10. |
TextEvent |
TextListener |
textChanged() |
TextEvent occurs
when an object's text change. |
11. |
WindowEvent |
WindowListener |
windowActivated(),
windowDeactivated(), windowOpened(), windowClosed(), windowClosing(),
windowIconfied() and windowDeiconified(). |
Window events occur
when a window's status is changed. |