我試圖讓JProgressBar
遞增1每1/100秒,而且目前我使用Thread.sleep(100)
while語句裏面,像這樣:進度條遞增1每隔100個第二
try {
while (i<=100){
doTime();
}
} catch (InterruptedException ex) {
Logger.getLogger(SplashScreen.class.getName()).log(Level.SEVERE, null, ex);
}
public void doTime() throws InterruptedException{
jLabel1.setText("sleeping");
Thread.sleep(100);
jLabel1.setText("start");
i++;
pb.setValue(i);
pb.repaint();
}
如果我通過執行調試System.out.println
它實時顯示,但擺動GUI凍結,直到它退出while循環任何人都可以幫助?
感謝
亞光
+1下面是javax.swing.Timer每隔100 ms更新一次'JLabel'的簡單示例。 http://stackoverflow.com/questions/2576353/stop-a-stopwatch/2576909#2576909 – trashgod 2010-04-07 16:37:01