I'm using Swing in NetBeans, creating a simple math game (I find it more viable than a calculator) whose goal is to add the random numbers of the buttons until it equals a number between 1 and 10000, which would be shown randomly. I used for
to try something cool, to do something like a simple timer to make the game more difficult. At the moment, taking the fact that Netbeans asked to add try
, catch
, does not show any error, however, jLabel
lblGameTime
is not counting time.
Here's my method (or rather, what I got to do, because I know I did it wrong, I just do not know where):
public void GameTime() {
int seconds = 120;
for (int i = seconds; i < 0; i++) {
lblGameTime.setText(String.valueOf(i));
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException ex) {
Logger.getLogger(tela1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}