Forums Login/signup

Parallel dragging

+Pie Number of slices to send: Send
Hello coders,


I'm experimenting with mouseListeners and I have an interesting problem (I think). I've searched the forum for similar posts but found none. Sorry if I missed any.

In my program I'm trying to move parts of shapes by dragging one of its points. I've already implemented the mousePressed() and mouseDragged() methods, and I can move single points. But I need to find out how many pixels the mouse pointer moved in X and Y and in which direction, so that I can apply the same vector to the other points.

In the mouseWheelEvent there is a method called getWheelRotation(), which returns the direction of the wheel. I need something alike for X and Y, instead of the actual new position getX() and getY() are returning.


Any thoughts? Thanks a bunch in advance,

O.
--
Sex is an emotion in motion.
-- Mae West
+Pie Number of slices to send: Send
 

Olaf Enulfson wrote:In my program I'm trying to move parts of shapes by dragging one of its points. I've already implemented the mousePressed() and mouseDragged() methods, and I can move single points. But I need to find out how many pixels the mouse pointer moved in X and Y and in which direction, so that I can apply the same vector to the other points.


One way is to simply have your Mouse input listener or mouse adapter save the location of the mouse on mousePressed method and store this in a variable local to this listener. Then it is trivial to calculate the change in x and y from this point in the mouseDragged method.
+Pie Number of slices to send: Send
 

Olaf Enulfson wrote:I'm trying to move parts of shapes


Also, much will depend on the details of just what you are trying to do. If you are trying to move a complete shape, then you may wish to use the Shape interface and affinetransforms. Otherwise you could encapsulate your shape yourself, and give it a move method. For instance:

SimpleBox.java


DragBoxPanel.java
+Pie Number of slices to send: Send
Pete, you are incredible.

I came up with your first suggestion too. I feel kind of bad for posting the question so soon. I should have given it more thought first.
But your second post blew me away. You're in a league of your own.

Thanks man. I appreciate it.

O.

reply
reply
This thread has been viewed 1807 times.
Similar Threads
Not quite programming the centipede game's centipede movement correctly (Java in Eclipse)
Make the thing bounce!
How to group these JLabels?
Stopping Animation
A probability problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Jun 28, 2025 16:25:21.