問題,我只能執行一次我的計時器。我知道它是因爲我調用了函數timer2.cancel();和timer1.cancel(); ::取消爲「永不再運行」。我需要一個替換函數,一個實際上停止計時器的函數,但是當我重新調度它時可以重新開始備份。我該如何去做呢?TimerTask啓動停止只執行一次
public void actionPerformed (ActionEvent e){
if (e.getSource()==jbtStart)
{
System.out.println("Start is pressed");
timer2.cancel();
timer1.schedule(new Task(), 0, delay);
}
else if (e.getSource()==jbtStop)
{
System.out.println("Stop is pressed");
timer1.cancel();
timer2.schedule(new Task2(), 0, delay);
}
不知道,從ActionListener只有codenipped,沒有明確什麼是你的定義(s)java.util.Timer – mKorbel