source code name: MouseDemo3.java
import java.awt.*;
import java.awt.event.*;
class MouseDemo3 extends Frame implements MouseListener
{
int x,y;
public MouseDemo3()
{
addMouseListener(this);
}
public void mousePressed(MouseEvent me)
{
x=me.getX();
y=me.getY();
repaint();
}
public void mouseReleased(MouseEvent me){
}
public void mouseClicked(MouseEvent me){
}
public void mouseEntered(MouseEvent me){
}
public void mouseExited(MouseEvent me){
}
public void paint(Graphics g)
{
g.setColor(Color.green);
g.fillOval(x,y,50,50);
}
public static void main(String[] args)
{
MouseDemo3 f=new MouseDemo3();
f.setTitle("Mouse Event program");
f.setSize(400,500);
f.setVisible(true);
}
}
output:
0 Comments
Post a Comment