• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mouse Drag Event

 
Alessandro Gigli
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am new to Java and I would like to ask if someone knows how to create an oval on a form, and with a mouse drag event drag the oval on the applet.
I thank you so much in advance.
 
Jasmine kaur
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Well you can draw oval by using method drawOval(int x, int y,int width, int height) this method is present in java.wat.Graphics class.
so you can use this method and trap the mouse motion and pass the values in the method. I hope this would work.
Please read the java.awt package carefully.
It would be great help to u.
Thanks.
 
juoyen lin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
you have to use mousePressed and mouseRealsed ,besides mouseDragged.
public void mousePressed(MouseEvent e)
{
//record the last position
last_x = e.getX();
last_y = e.getY();
...
}
public void mouseReleased(MouseEvent e)
{
//count the delta
deltax = last_x - e.getX();
deltay = last_y - e.getY();
...
}
this is a simple sample, maybe can't statisfy what you want.
but you can refference.
(sorry,my english is poor)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic