当计时器达到零时,我试图从窗格中删除元素,更具体地说是标签和文本区域。但是,当计时器达到 0 并且我调用此方法时,我会收到此异常。
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Not on FX application thread; currentThread = AWT-EventQueue-0
代码:
ActionListener timeListener = new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
gameTime--;
System.out.println(gameTime);
if(gameTime == 0){
endGame();
}
}
};
endGame() 方法:
public void endGame(){
timer.stop();
System.out.println("Score: " + score);
view.gamePane.getChildren().removeAll(view.lblQuestion, view.tfAnswer);
}