This problem probably has a really simple solution but it has me stumped. I am basically trying to get the code in my main() method to wait (do nothing) until the user clicks on a certain JButton component.

What I tried was to put a small loop in the main() method that would exit when a flag variable was set by my MouseEventListener method like so:


In main() ->


while(!clicked) ; //do nothing


In Listener ->


public void mouseClicked(...)

{ clicked = true; }


Not only does this not work but it wastes a lot of CPU time doing nothing! Please tell me how to do this right!

Thanks ahead of time!