checking for mouseReleased event

Hi,

I am trying to find out how to "look ahead" if a mouseReleased event is about to happen, from within a mousePressed method. Here is the pseudocode:

mousePressed(....){

while( mouseNotreleased){

//perform some long running task here.

}

}

mouseReleased(....){

mouseNotReleased = false;

}

from this pseudocode, once a user pressed the mouse, the mousePressed method is called and it will get in a while loop that will not break out of the loop UNTIL the mouse is released.

But the problem is it seems that as long as I am inside the while loop, the mouseReleased event does not get queued even if I've already released the mouse.

I tried ToolKit.getSystemEventQueue().peek() from inside the mousePressed method, but it returns null...... again, this suggests that the mouseReleased event has not been queued yet.

appreciate anyone who can help.

[933 byte] By [fsilva21a] at [2007-10-2 12:34:30]
# 1

You could use a timer and a timertask. Otherwise, you could just create a boolean flag somewhere that gets flipped when the mouse button is released.

The reason you're not getting your mouseReleased event is that you're doing all this work in the UIThread. You've got to create another thread and either a Runnable or a Timer / Timertask

tjacobs01a at 2007-7-13 9:34:25 > top of Java-index,Security,Event Handling...
# 2

You cannot use your algorithm/pseudocode to accomplish what you want to do. All events are by default executed in the event dispatching thread and if you do keep doing something in a event method - it cannot be dependent of code in another since that code isn't executed as long as the first event isn't handled (ie. Catch 22).

mange@orua at 2007-7-13 9:34:25 > top of Java-index,Security,Event Handling...
# 3

thanks guys. I totally spaced out, I forgot the basic rule regarding the EventDispatchThread. You guys are right, the EventDispatchThread will first invoke the mousepressed event and until my code exits the mousepressed method, the EventDispatchThread cannot move on to invoke the mousereleased event.

thanks again for the quick response.

fsilva21a at 2007-7-13 9:34:25 > top of Java-index,Security,Event Handling...