Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Keeping location of a moving rectangle based on coordinate points?

 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay so I have a set of rectangles that I need to be able to move.





Basically at this point once it gets the x,y values that are inside the rectangle it will move the coordinates of the Rectangle's x,y to where I'm moving it, so my mouse position is always 0,0. What I want is to be able to have the rectangle move based on it's exact position clicked i.e, if I click 20,20 inside the rectangle I want to always be at 20,20.

So what exactly I'm looking for is if there is a method or something that I know where exactly inside the rectangle I am and the distance from that point to the outside to recreate my rectangle. so if I am at 20,20 in a 100,100 rectangle, then I should know I'm 20 from the xtop, ytop and 80 from xbot,ybot.

Thanks,

~JO
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I'm reading this right, have a look at the Dragger class in my 2nd reply here:

http://www.coderanch.com/t/573169/GUI/java/questions-JPanel
 
Jay Orsaw
Ranch Hand
Posts: 356
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Michael Dunn wrote:If I'm reading this right, have a look at the Dragger class in my 2nd reply here:

http://www.coderanch.com/t/573169/GUI/java/questions-JPanel



Thanks, will check it out in a few.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic