Expt 9

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy