I'm trying to implement a dragging algorithm for swing components where they can be clicked and dragged. However, it appears that my movements are in the correct directions, but extremely exaggerated. As in, a tiny bit of mouse movement causes a very disproportionate move in the shape.
Here is the code where I determine the movement:
(xStart
and yStart
are the coordinates where the mouse is first clicked to begin the drag)
The component has a move(int deltaX, int delatY)
method which does just that. An example move method for a line component looks like this:
@Override
public void move(int dx, int dy) {
this.x1 += dx;
this.y1 += dy;
this.x2 += dx;
this.y2 += dy;
}
The move method is called like this, where e
is a mouse drag event:
currentShape.move(e.getX() - (int) xStart, e.getY() - (int) yStart);