The Adapter classes are an abstract class for receiving various events and the methods in these classes are empty.

These classes exist as a convenience for creating the listener objects.

  1. The Java provides a special feature called as an adapter class that can simplify the creation of the event handlers in certain situations.
  2. An adapter class provides empty implementation of all the methods in an event listener interface that is this class itself write the definition for methods which are already present in a particular event listener interface and However these definitions does not affect the program flow or meaning at all.
  3. The Adapter classes are very useful when we have to receive and process only some of the events that are already handled by a particular event listener interface.
  4. We can define a new class which can act as an event listener by extending one of the adapter classes & implementing only those events in which we are interested.
  5. Example- Suppose that we want to use the MouseClicked event or method from MouseListener and if we do not use adapter class then unnecessarily we have to define all the other methods from MouseListener as MouseReleased, MousePressed etc.
  6. But when we use adapter class then we can only define MouseClicked method and not to worry about other method definitions because adapter class provides an empty implementation of all the methods in an event listener interface.
  7. Below is the Table that Indicates Listener Interface with their respective adapter classes.

Capture5

AWT Adapters:

The Following is the list of some commonly used adapters while listening a GUI event in AWT.

Capture6

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

©2018 MYBSCIT.com. An initiative by some failures to make student scholars.

or

Log in with your credentials

Forgot your details?