Showing posts with label Adapter classes in Java with example. Show all posts
Showing posts with label Adapter classes in Java with example. Show all posts

Monday, 13 May 2019

Adapter classes in Java - Online Help

Adapter classes in Java:

An adapter class in Java has implemented as an interface and provides an empty implementation of all methods in a particular listener interface.

The adapter classes are present in the java.awt.event package.The various java.awt.event adapter classes and the interfaces are as follow:

Adapter classes
Implements Interface
Component Adapter
Component Listener
Container Adapter
Container  Listener
Focus Adapter
Focus Listener
Key Adapter
Key Listener
Mouse Adapter
Mouse Listener
MouseMotion Adapter
MouseMotion Listener
Window Adapter
Window Listener


Sample Program Adapter classes in Java:

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class adapterdemo extents Applet
{
public void init()
{
setBackground(Color.yellow);
addMouseListener(new Adpcls1(this));
addMouseMotionListener(new Adpcls2(this));
}
}
class Adpcls1 extents MouseAdapter
{
adapterdemo mad;
public Adpcls1(adapterdemo mad)
{
this.mad=mad;
}
public void mouseReleased(MouseEvent me)
{
mad.setBackground(Color.yellow);
mad.repaint();
}
}
class Adpcls2 extends MouseMotionAdapter
{
adapterdemo mad;
public Adpcls2(adapterdemo mad)
{
this.mad=mad;
}
public void mouseDragged(MouseEvent me)
{
mad.setBackground(Color.green);
mad.repaint();
}
}