所以,我基本上需要一个每5秒运行一次的命令,但计时器不起作用... 我尝试了很多不同的方法, 唯一有效的是Thread.sleep(毫秒); 但这会导致我的整个游戏停止工作... 如果我尝试使用计时器,例如:
Timer timer = new Timer(1000, new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("Hey");
}
});
timer.setRepeats(true);
timer.setCoalesce(true);
timer.start();
如何使计时器正确触发?