我正在研究一个JFrame计时器,每次按下启动程序冻结在这里都是我的代码:
public void startTime() throws InterruptedException{
Thread thread = new Thread();
for(int i = 0;i<10000;i++){
seconds++;
timeLabel.setText(hours+" : "+ minutes +" : "+seconds);
switch(seconds){
case 60:
seconds = 0;
minutes++;
break;
}
switch(minutes){
case 60 :
minutes = 0;
seconds = 0;
hours++;
break;
}
thread.sleep(700L);
}
}
@Override
public void actionPerformed(ActionEvent e) {
try {
startTime();
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
我试图这样做,以便当我按下按钮它启动计时器任何想法如何解决这个问题?
你在Swing事件线程上调用Thread.sleep.
这个:
Thread thread = new Thread();
Run Code Online (Sandbox Code Playgroud)
什么都不做.