This week's book giveaway is in the Cloud forum. We're giving away four copies of Terraform in Action and have Scott Winkler on-line! See this thread for details.
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.
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.
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:
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.
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop