Hi,
In my applet I currently have a loop. I am trying to make a "pause" button. So that when this button is pressed, the loop will pause, and wait for a "start" button to be pressed to continue.
Any advice?
Thanks!
Printable View
Hi,
In my applet I currently have a loop. I am trying to make a "pause" button. So that when this button is pressed, the loop will pause, and wait for a "start" button to be pressed to continue.
Any advice?
Thanks!
What are you doing in the loop? Is there one place in the loop where you want to "pause" the execution?
And then have it start again at the same place?
One solution off the top of my head: Break the loop into two parts at the place you want to pause.
Have a method that calls part one and then part two.
have a boolean the method can test to see if it is to execute part two. If not, set a flag indicating the loop was paused and exit.
When the button is pressed, start a Thread to execute the method that calls the two parts. The method can see it was paused and will start the execution at the second part.
There can be some variables that will have to be saved to be able to restore the state of the loop.
Another solution could be to put the loop in its own thread and use wait and notify to stop and start the thread.
use an event listener and have it when you hit the start button it sets a variable to 0 and when you hit pause it sets the variable to 1. Then in your loop do something like this:
while(variable < 1){
//stuff
}
I think that we need to know more about what exactly is going on, that the OP needs to answer Norm's questions before we can give intelligent advice. For all we know all he needs is a Swing Timer that he can pause and restart at will.
Hmmm, how can it be set to false?Code:System.out.println(heardOfBoolean);
The irony eludes you.
Do you see the irony in that?Code:boolean heardOfBoolean = false;
No. Did you read the rest of the posts to see that I was just having a bit of fun?
From my point of analyzation, you need a Javax Timer that increment a variable every 1 sec. then pause it when press the pause button.