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?