1

I've created a Java-Application to add/remove and show a random number of points on a JPanel. It is possible to move the points per drag&drop. To undo the last actions I buffer the points.

My question: if a point will moved via 'mouseDragged', is it possible to save the first mouseposition while the drag begins? I've tried the following:

public void mouseDragged(MouseEvent e) {
    int x = e.getX();
    int y = e.getY();

    if (!points.isEmpty() && curPointIndex > -1) {
        if (move == false) {
            pointmove = new Point(x,y);
            move = true;
        }
    }
}

The method mouseReleased change the variable move back to false. The variable pointmove should save the first point, but it changes all the time while the mouse is dragged.

Could anyone discribe why or what I can to do differently?

Guillaume S
  • 1,462
  • 2
  • 19
  • 31
t1n1tus
  • 99
  • 1
  • 8

1 Answers1

0

As Arnaud mentioned, you can use mousePressed to store the initial point:

        @Override
        public void mousePressed(MouseEvent e)
        {
            Point initialPoint = e.getPoint();
        }
kAliert
  • 768
  • 9
  • 21