Expt 9
Expt 9
Expt 9
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="AdapterDemo" width=300 height=300></applet>*/
public class AdapterDemo extends Applet
{
public void init()
{
addMouseListener(new MyMouseAdapter(this));
addMouseMotionListener(new MyMouseMotionAdapter(this));
}
}
class MyMouseAdapter extends MouseAdapter
{
AdapterDemo adapterDemo;
public MyMouseAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo=adapterDemo;
}
public void mouseClicked(MouseEvent me)
{
adapterDemo.showStatus("Mouse Clicked");
}
}
class MyMouseMotionAdapter extends MouseMotionAdapter
{
AdapterDemo adapterDemo;
public MyMouseMotionAdapter(AdapterDemo adapterDemo)
{
this.adapterDemo=adapterDemo;
}
public void mouseDragged(MouseEvent me)
{
adapterDemo.showStatus("Mouse Dragged");
}
}
Output:
Code:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code="Exp9_1" width=300 height=300></applet>*/
public class Exp9_1 extends Applet implements MouseMotionListener
{
int x,y;
public void init()
{
addMouseMotionListener(this);
addMouseMotionListener(new MyMouseMotionAdapter(this));
}
public void paint(Graphics g)
{
g.drawString("Mouse entered.",50,20);
}
public void mouseMoved(MouseEvent me)
{
x=me.getX();
y=me.getY();
showStatus("Moving mouse at "+x+","+y);
}
public void mouseDragged(MouseEvent me)
{
}
}
class MyMouseMotionAdapter extends MouseMotionAdapter
{
Exp9_1 adapterDemo;
public MyMouseMotionAdapter(Exp9_1 adapterDemo)
{
this.adapterDemo=adapterDemo;
}
public void mouseEntered(MouseEvent me)
{
adapterDemo.showStatus("Mouse Dragged");
}
}
Output: