我有一个问题在我的代码,因为我不能停止swing.timer如何停止摆动计时器?
//一些代码在这里
我试图if语句把一个但它不工作。
Static int gScore = 1000;
t = new Timer(100, new ActionListener() {
public void actionPerformed(ActionEvent e) {
score01.setText("score: " + gScore);
gScore--;
}
});
t.start();
t.setRepeats(true);
if(gScore== 970){//A
t.stop();
t.setRepeats(false);
}//A
我想停止计时,当它达到一个给定值,并移除它的JFrame里面
该代码甚至不会编译。你必须说的不仅仅是“它不工作”。把调试语句放在那里看看发生了什么。 – Kayaman
请格式化代码,并发布完整的方法。 – UDPLover