When should we use an event adapter class?

When should we use an event adapter class?

A listener’s class has to implement Listener interface which means all the methods of the interface must be defined in the class. This will become a tedious work when we have many methods in interface and we want to implement only one method. For this we have to define all the methods in a class. So to avoid this type of situation we use Event adapter class. The event listener interfaces that contain more than one method have a corresponding event adapter class that implements the interface and defines each method in the interface with an empty method body. Instead of implementing an event listener interface, you can extend the corresponding event adapter class and define only those methods in which you are interested.

The WindowAdapter class is an example of an event adapter class. It implements WindowListener, and defines its seven methods with empty method bodies.
Component and container classes in Java
The Component class is found under java.awt package. The container class is the subclass of Component class...
Difference between runtime and plain exception
Runtime Exceptions like out-of-bound array indices, NullPointerException , AirthmeticException are all subclasses of java.lang.RuntimeException class...
Life cycle for stateless and stateful beans
Stateless Session Bean Lifecycle: The stateless session bean does not become passive, so its life cycle has two stages:...
Post your comment