You are on page 1of 4

PRACTICAL NO:06

Write a program making use of adapter class.


Aim:
Write a program making use of adapter class.

Theory:
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.

dapter class is a simple java class that implements an interface with only EMPTY


implementation . Instead of implementing interface if we extends Adapter
class ,we provide implementation only for require method.

What is Adapter class

 The Adapter class provides the default modification of all methods of an interface;
we don't need to modify all the methods of the interface so we can say it reduces
coding burden. Sometimes or often we need a few methods of an interface. For
that, the Adapter class is very helpful since it already modifies all the methods of
an interface and by implementing the Adapter class, we only need to modify the
required methods.
 
Advantages of the Adapter class

 Assists unrelated classes to work together.


 Provides a way to use classes in multiple ways.
 Increases the transparency of classes.
 Its provides a way to include related patterns in a class.
 It provides a pluggable kit for developing applications.
 It makes a class highly reusable.

The following examples contain the following Adapter classes:


 ContainerAdapter class.
 KeyAdapter class.
 FocusAdapter class.
 WindowAdapter class.
 MouseAdapter class.
 ComponentAdapter class.
 MouseMotionAdapter class.
 Etcetera

Program:
Output:

You might also like