Friday, 10 August 2012

program to use of MosueListener and MouseMotionListener interfaces in applet.



import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="MyMouse" width=500 height=400>
</applet>
*/
public class MyMouse extends Applet implements MouseListener,MouseMotionListener
{
String msg=" ";
int x,y;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="click";
showStatus("x--"+x+"  y--"+y +"moused clicked");
repaint();
}
public void mouseEntered(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="";
showStatus("x--"+x+"  y--"+y +"moused Enterd");
repaint();
}
public void mouseExited(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="";
showStatus("x--"+x+"  y--"+y +"moused Exited");
repaint();
}
public void mousePressed(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="";
showStatus("x--"+x+"  y--"+y +"moused Pressed");
repaint();
}
public void mouseReleased(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="Released";
showStatus("x--"+x+"  y--"+y +"moused Released");
repaint();
}
public void mouseDragged(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="*";
showStatus("x--"+x+"  y--"+y +"moused Dragged");
repaint();
}
public void mouseMoved(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="";
showStatus("x--"+x+"  y--"+y +" moused moved");
repaint();
}
public void paint(Graphics g)
{
 
g.drawString(msg,x,y);
}
}