Javatpoint Logo
Javatpoint Logo

Java Adapter Classes

Java adapter classes provide the default implementation of listener interfaces. If you inherit the adapter class, you will not be forced to provide the implementation of all the methods of listener interfaces. So it saves code.

The adapter classes are found in java.awt.event, java.awt.dnd and javax.swing.event packages. The Adapter classes with their corresponding listener interfaces are given below.

java.awt.event Adapter classes

Adapter classListener interface
WindowAdapterWindowListener
KeyAdapterKeyListener
MouseAdapterMouseListener
MouseMotionAdapterMouseMotionListener
FocusAdapterFocusListener
ComponentAdapterComponentListener
ContainerAdapterContainerListener
HierarchyBoundsAdapterHierarchyBoundsListener

java.awt.dnd Adapter classes

Adapter classListener interface
DragSourceAdapterDragSourceListener
DragTargetAdapterDragTargetListener

javax.swing.event Adapter classes

Adapter classListener interface
MouseInputAdapterMouseInputListener
InternalFrameAdapterInternalFrameListener

Java WindowAdapter Example

Output:

java awt windowadapter example 1

Java MouseAdapter Example

Output:

java awt mouseadapter example 1

Java MouseMotionAdapter Example

Output:

java awt mousemotionadapter example 1

Java KeyAdapter Example

Output:

java awt keyadapter example 1



Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA