As shown in this example, one approach is to maintain two Point
instances. One holds the last mouse location; the other holds the desired target location; both are in in component-relative coordinates.
In mousePressed()
,
Initialize the last mouse location.
Optionally, mark the target as selected.
Invoke
repaint()
to display the selected appearance.
In mouseDragged()
,
Update the target location by the difference between the new and old mouse locations.
Update the last mouse location to the current mouse location.
Invoke
repaint()
.