Java program to implement mouse event in an applet.
Below code is used to perform the implementation of mouse event in an applet:
import java .awt.*;
import java.applet.Applet;
import java.awt.event.*;
/*
<applet code="Mouseevents.class" width="300" height="300">
</applet>
*/
public class Mouseevents extends Applet implements MouseListener,MouseMotionListener
{
String msg=" " ;
int x=0,y=0;
public void init()
{
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseClicked(MouseEvent me)
{
x=10;
y=20;
msg="mouse clicked";
repaint();
}
public void mouseEntered(MouseEvent me)
{
x=10;
y=20;
msg="mouse entered";
repaint();
}
public void mouseExited(MouseEvent me)
{
x=10;
y=20;
msg="mouse exited";
repaint();
}
public void mousePressed(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="down";
repaint();
}
public void mouseReleased(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="up";
repaint();
}
public void mouseDragged(MouseEvent me)
{
x=me.getX();
y=me.getY();
msg="*";
showStatus("Dragging mouse at"+x+","+y);
repaint();
}
public void mouseMoved(MouseEvent me)
{
showStatus("Moving mouse at"+me.getX()+","+me.getY());
}
public void paint(Graphics g)
{
g.drawString(msg,x,y);
}
}