我希望有人可以帮助我解决我遇到的计时器问题。当 timer.start() 运行时,计时器启动。然而,它似乎在无休止地重复。
我只需要计时器执行一次。如果 timer.setRepeats(false) 不起作用,我该如何实现?
ActionListener updatePane = new ActionListener() {
public void actionPerformed(ActionEvent ae) {
try {
msgPaneDoc.insertString(msgPaneDoc.getLength(), "CLICK",
msgPaneDoc.getStyle("bold_style"));
} catch (BadLocationException ex) {
}}};
Timer timer = new Timer(3000,updatePane);
timer.start();
timer.setRepeats(false);