• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

method for mouse when the mouse stopped Dragging but is not released yet

 
Bobby Marvikuan
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • clicked
  • depressed
  • released
  • enters the Component
  • leaves the Component
  • moved
  • and dragged
  • 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.
     
    Darryl Burke
    Bartender
    Posts: 5148
    11
    Java Netbeans IDE Opera
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic