Need help with a timer/thread/loopish thing.
Hi.
I've made a little game with a timer down the right corner. I want the timer to stop when you press Escape, currently if you press escape the menu comes up but the timer continues.
Edit: Int tic = 30; >.<
And don't mind the "SetVisible", this run method starts the game, setVisible makes the game frame visible..
Code:
public void run() {
setVisible(true);
for(int dup = 0; dup < 30; dup++){
try {
tic--;
Thread.sleep(1000);
} catch (Exception ex) {}
left.setText("Time left: " + tic);
if(tic == 0){
finish b = new finish();
new finish();
panel.setEnabled(false);
randomNumber = 1;
randomNumber2 = 1;
}
}
}
This timer starts at 30 and counts down as time passes.
I tried to do like if(rest = false):thread.sleep(1000), else if(rest = true) thread.sleep(10000000), the rest boolean was connected to the escape button..that way of doing it worked, kinda, the timer stopped when you pressed escape. But it didn't start again when you press "Resume" ^-^
And also, is there a JFrame command like: setMoveable(false)?