Welcome to the CSC Q&A, where you can get help (and share your knowledge) about computer science!

How do I get the program to WAIT until the mouse to be clicked?

+6 votes

A student came into my office to ask this.  Good question.  

If you put in a panel.sleep(<millis>) then that will wait for a little while, but then continue after that time.  What we want to do is *repeatedly* sleep for a little bit, and then check whether the mouse is clicked, and then sleep for a bit, and then check whether the mouse is clicked... and as long as the mouse has NOT been clicked, we should keep doing this.  

Once the mouse is clicked, then the loop should finish and the rest of your program should continue running.

You'll want to use a WHILE loop for this, along with the panel.checkMouseClicked() method which returns a boolean value.

Hope that helps!

asked Jan 22, 2015 in (Winter 14) by Forrest Stonedahl (3,438 points)

1 Answer

+1 vote
I suggest using a low number like 50 for the <millis>.
answered Jan 22, 2015 by B Hook (100 points)
Good idea -- but why is that?
...