我有一個問題在我的代碼,因爲我不能停止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