import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class mousemove extends JFrame implements MouseListener,MouseMotionListener
{
int x,y,X,Y;
mousemove()
{
addMouseListener(this);
addMouseMotionListener(this);
x=0;
y=0;
}
public void mouseEntered(MouseEvent me)
{
}
public void mousePressed(MouseEvent me)
{
}
public void mouseClicked(MouseEvent me)
{
}
public void mouseReleased(MouseEvent me)
{
}
public void mouseMoved(MouseEvent me)
{
x=me.getX();
y=me.getY();
repaint();
}
public void mouseDragged(MouseEvent me)
{
}
public void mouseExited(MouseEvent me)
{
}
public void paint(Graphics g)
{
super.paint(g);
g.drawString("x="+x,50,50);
g.drawString("Y="+y,90,50);
}
public static void main(String args[])
{ mousemove f=new mousemove();
f.setTitle("demo of mouse event");
f.setSize(400,400);
f.setVisible(true);
}
}
No comments:
Post a Comment