I'm trying to create a 1 hour countdown timer. I'm using a label and a button. When i press the start button the countdown should start but instead of that my window freezes. I searched in many sites and they said that the problem is the Thread.sleep(1000) but i didn't get a clear answer on how i can fix my problem!
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
label.setText("60:00");
for(int i=59;i>=0;i--)
{
for(int j=59;j>=0;j--){
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(i<10 && j<10){
label.setText("0"+i+":0"+j);
}
else if(i<10 && j>=10){
label.setText("0"+i+":"+j);
}
else if(i>=10 && j<10){
label.setText(i+":0"+j);
}
else {
label.setText(i+":"+j);
}
}
}
}
});