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.
The WindowAdapter class is an example of an event adapter class. It implements WindowListener, and defines its seven methods with empty method bodies.
Comments
Post a Comment