I have a JFrame
on which I want to simulate a countdown (like a rocket launch). So I set up the frame by hiding various controls (setVisible(false)
) and displaying a JLabel
with the text (this is the text that is supposed to countdown: 3, 2, 1, Go).
The text on that JLabel
starts out at "3". My intent is to simply have the execution of the program wait for 1 second, then change the text to "2", wait another second, change to "1", etc.). At the end, I hide the JLabel
and redisplay all of the controls and everything proceeds as normal.
What I am doing isn't working. It seems to wait for the correct amount of time, and when it is done, my JFrame looks great and works as intended. But during the 4 seconds of the countdown method, all I see is a white JFrame. Not the 3, 2, 1 that I want.
Here is my code. Can anyone see what I am doing wrong? Thanks!
public void countdown() {
long t0, t1;
myTest.hideTestButtons(true);
myTest.repaint();
t0 = System.currentTimeMillis();
do {
t1 = System.currentTimeMillis();
} while ( (t1 - t0) < 1000);
myTest.TwoSeconds();
myTest.repaint();
t0 = System.currentTimeMillis();
do {
t1 = System.currentTimeMillis();
} while ( (t1 - t0) < 1000);
myTest.OneSecond();
myTest.repaint();
t0 = System.currentTimeMillis();
do {
t1 = System.currentTimeMillis();
} while ( (t1 - t0) < 1000);
myTest.Go();
myTest.repaint();
t0 = System.currentTimeMillis();
do {
t1 = System.currentTimeMillis();
} while ( (t1 - t0) < 1000);
myTest.hideTestButtons(false);
myTest.repaint();
}
public void TwoSeconds() {
lblCountdown.setText("2");
}
public void OneSecond() {
lblCountdown.setText("1");
}
public void Go() {
lblCountdown.setText("Go!");
}