Event Listeners

The convention for all event-listener interfaces is for names to end in the word Listener. Like the convention for event objects, this helps to identify the purpose of the interface. All of the event-listener interfaces provided by the core Java class libraries follow this convention.

The methods that are defined in the event-listener interfaces should conform to the standard design pattern for event-notification methods. This allows the programmer to understand the purpose of the methods without having to dig through piles of documentation. The method signature for an event-listener method is as follows:

void <eventOccurenceMethodName>(<EventObjectType> evt);

The event occurrence method name should describe the event. The event object is passed when the event is fired. This object should be derived from the class java.util.EventObject. You can also include a throws clause that lists any checked exceptions that might be thrown when this method is invoked.

Get Developing Java Beans 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.