【发布时间】:2014-05-29 05:14:47
【问题描述】:
我需要我的计时器重新启动,或者至少在执行某行代码后添加另一个延迟。
private static class ButtonHandler implements ActionListener {
public void actionPerformed (ActionEvent e) {
final JButton button = (JButton)e.getSource();
Timer timer = new Timer(1000, new ActionListener() {
public void actionPerformed(ActionEvent e) {
String tc = random();
them.setText("They chose: " + tc + "!");
if (button == rock) {
whoWins("rock", tc);
} else if (button == paper) {
whoWins("paper", tc);
} else if (button == scissors) {
whoWins("scissors", tc);
}
yourWins.setText("Your wins: " + yw);
theirWins.setText("Their wins: " + tw);
}
});
timer.setRepeats(false);
timer.start();
}
}
我想在之后立即实现计时器的第二次延迟
them.setText("they chose: " + tc + "!");
但我不确定如何执行此操作,我应该重新启动计时器吗?如果是,我将在哪里编写那行代码?提前致谢。
【问题讨论】:
-
它应该在消息显示后立即延迟(他们选择:...),无需用户交互。它本质上应该是两个延迟,中间有一个暂停,无论在屏幕上显示第一条消息需要多长时间。
-
不再需要了,非常感谢大家的帮助,我终于可以在睡眠之外开发我的简单程序了。