import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*
<applet code="MouseMovingPosition" width=300 height=100>
</applet>
*/
public class MouseMovingPosition extends Applet implements MouseMotionListener
{
String msg = "";
int mouseX = 0, mouseY = 0; // coordinates of mouse
public void init()
{
addMouseMotionListener(this);
}
// Handle mouse dragged.
public void mouseDragged(MouseEvent me)
{
// save coordinates
mouseX = me.getX();
mouseY = me.getY();
msg ="Mouse dragged at\n("+ mouseX+","+mouseY+")";
repaint();
}
// Handle mouse moved.
public void mouseMoved(MouseEvent me)
{
mouseX = me.getX();
mouseY = me.getY();
msg ="Mouse moved at\n("+ mouseX+","+mouseY+")";
repaint();
}
// Display msg in applet window at current X,Y location.
public void paint(Graphics g)
{
g.drawString(msg, mouseX, mouseY);
}
}