Program:
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Color;
public class MouseMotionListenerDemoC extends Frame
implements MouseMotionListener
{
Label
l1;
MouseMotionListenerDemoC()
{
addMouseMotionListener(this);
l1=new
Label("Mouse not found yet....Get the mouse on to the frame!!!");
l1.setBounds(20,50,500,50);
add(l1);
setSize(500,500);
setLayout(null);
setVisible(true);
}
public
static void main(String a[])
{
MouseMotionListenerDemoC
mmldc=new MouseMotionListenerDemoC();
}
public
void mouseDragged(MouseEvent me)
{
l1.setText("Mouse
Dragged"+me.getX()+" , "+me.getY());
Graphics
g=getGraphics();
g.setColor(Color.red);
g.fillOval(me.getX(),me.getY(),20,20);
}
public
void mouseMoved(MouseEvent me)
{
l1.setText("Mouse
Moved"+me.getX()+" , "+me.getY());
//Graphics
g=getGraphics();
//g.setColor(Color.green);
//g.fillOval(me.getX(),me.getY(),20,20);
}
}
output:-
run the program as follows
javac MouseMotionListenerDemoC.java
java MouseMotionListenerDemoC
Nice
ReplyDeleteInteresting. .... Hope u do more.. !
ReplyDeleteYour content is nothing short of bright in many forms. I think this is friendly and eye-opening material. I have gotten so many ideas from your blog. Thank you so much. containment coating
ReplyDelete