Java Countdown Timer
807580Dec 13 2009 — edited Dec 13 2009Hello everyone!
I'm trying to make a timer in Java that counts down from 5 minutes to 0, but I can't do it. I can't find a way to make the program wait for a second then decrement the minutes and seconds... Can anyone help?
Here is my code, please help me!
package little_testing;
import java.util.*;*
import javax.swing.;
import java.awt.*;
public class Main {
public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JLabel time_var = new JLabel("");
int i=5;
while (i>0){
time_var.setText(""+i);
//this is the place where i think i should put the part of the program that makes it wait for 60 seconds and then change the JLabel
}
frame.add(panel);
panel.add(time_var);
frame.setVisible(true);
frame.setSize(500,500);
}
}
I could try to change the program to make it wait one second and count them up till they're 60 and then decrement the minutes... Anyway, the idea is that I would like to know how to make the program count one second / one minute.
Please help!
Thanks!