First page Back Continue Last page Graphics

Using Event Listeners


Using Event Listeners

Components can generate events, which are occurrences that take place as users interact with an application, such as when they click a button or change a value. There are also events, such as gaining or losing focus, that are not the result of user interactions.

If there is a listener for the event, the event communicates some information about what happened, so that the listener can respond. An event, then, is a component’s way of letting a listener know that something happened.

An event listener is a class that implements one of the listener interfaces and contains code to respond to the event. A component has mechanisms to register and deregister event listeners for the types of events that are generated by the component.