0% found this document useful (0 votes)
35 views4 pages

Expt 9

This document defines two classes - MyMouseAdapter and MyMouseMotionAdapter - that extend the MouseAdapter and MouseMotionAdapter classes. These adapter classes are used to listen for mouse click and drag events in the AdapterDemo applet class. When a mouse click or drag occurs, the adapter classes call the showStatus method on the AdapterDemo class to display the event in the status bar.

Uploaded by

Mdsaad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views4 pages

Expt 9

This document defines two classes - MyMouseAdapter and MyMouseMotionAdapter - that extend the MouseAdapter and MouseMotionAdapter classes. These adapter classes are used to listen for mouse click and drag events in the AdapterDemo applet class. When a mouse click or drag occurs, the adapter classes call the showStatus method on the AdapterDemo class to display the event in the status bar.

Uploaded by

Mdsaad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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:

You might also like