1

我想使用该方法javax.swing.Timer创建一个从 3:00 开始,然后下降到 0:00 的计时器。我不知道如何使用这种方法以及如何进行。从现在开始,我有这个代码,但我不知道它是否好。可以肯定的一件事是它不起作用。

private javax.swing.Timer timer = new javax.swing.Timer(1000, new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent ae) {
        int minute = 3;
        int seconde = 60;
        do {
            lblTimer.setText(Integer.toString(seconde));
            seconde--;
        } while (seconde != 0);
    }
}); 
4

1 回答 1

2

在这个例子中,aTimerButton在传递给构造函数的延迟之后做出响应,例如

new TimerButton("Back in three minutes", 3 * 60 * 1000));

您将在到期StopListener时采取所需的操作,例如Timer

private class StopListener implements ActionListener {

    @Override
    public void actionPerformed(ActionEvent e) {
        timer.stop();
        // further actions here
    }
}

有关更多详细信息,请参阅如何使用摆动计时器

于 2014-10-18T23:30:19.983 回答