Event Listeners

If a class wants to respond to a user event under the Java 2 event-handling system, it must implement the interface that deals with the events. These interfaces are called event listeners.

Each listener handles a specific kind of event, and a class can implement as many of them as needed.

The event listeners in Java include each of the following interfaces:

  • ActionListenerAction events, which are generated by a user, taking an action on a component, such as a click on a button

  • AdjustmentListenerAdjustment events, which are generated when a component is adjusted, such as when a scrollbar is moved

  • FocusListenerKeyboard focus events, which are generated when a component such as a text field gains or loses the focus

  • ItemListener

Get Sams Teach Yourself Java 2 in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.