我有一个游戏方法,这个方法里面有定时器,只有在特定的情况下(如果下面的条件),我想停止定时器…但出于某种原因,它导致我崩溃。
public model() {
public game() {
Timer timer = new Timer(50, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
....
//draw shapes on JFrame
if (model.Life == 0) { //specific condition
model.timer.stop(); //timer is making a crash here
}
repaint();
}
});
timer.start();
}