有沒有辦法輕鬆將thread.sleep轉換爲javax.swing.timer?如何將thread.sleep轉換爲javax.swing.timer?
我需要這樣做的原因是當您按下按鈕時停止用戶界面凍結,以便您可以實現暫停按鈕。
代碼示例:
btnStartTiming.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent arg0) {
try{
inputA = Double.parseDouble(txtEnterHowLong.getText()); //Changes double to string and receives input from user
}catch(NumberFormatException ex){
}
while (counter <= inputA){
txtCounter.setText(counter + "");
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
System.out.println(counter);
counter++;
}
}
});
這是什麼問題? –
我不確定如何在此代碼中實現javax.swing.timer。 – Harold
教程正在等待。 –