Hello. I am interested how to do this thing:
for e.g., I want to draw a square when the mouse stopped Dragging but is not released yet? I tried mouse pressed but it calls it only at the beginning. So, I have no idea, any help?
Cheers in advance!
Can’t think of any offhand, even though I once had to program the same sort of thing. There are 7 mouse methods that I can remember, in the MouseListener interface and in MouseMotionListener. They are for when the mouse is
enters the Component
leaves the Component
I think mouseDragged is the most likely to work. Try the two opposite corners with pressed giving you one pair of x, y (first corner) and dragged (repeatedly) giving you the x, y for the other corner.
If you want to draw a square (rectangle?) when the drag is stopped but don't want to draw while the mouse is still being dragged, you need to start by defining 'stopped' in terms of time/duration and drift/pixels (since the user may, like me, have a shaky hand) even before you begin coding.
You'd want to use a Swing Timer for that.
There are no new questions, but there may be new answers.