【发布时间】:2018-01-04 15:17:21
【问题描述】:
在 JavaFX 应用程序中显示我的 TextInputDialog 时遇到问题。在代码中:
TextInputDialog tid = new TextInputDialog("Your name");
tid.setTitle("Table");
tid.setHeaderText("You have won!");
tid.setContentText("Enter your name: ");
tid.showAndWait();
我遇到了这样的错误:
Exception in thread "Timer-2" java.lang.IllegalStateException: Not on FX application thread; currentThread = Timer-2
是的,我在我的应用程序中使用了三个或四个计时器。
GitHub - https://github.com/verygoodat/FlappyBox /src/Application/GameController/ - 函数 setState(int), switch(2),我应该在游戏中创建一条消息,但我不能。 那么,什么可能导致这个问题呢?
这个Platform.runLater(() -> tid.showAndWait()) 没用
case 2://pause
TextInputDialog tid = new TextInputDialog("Ваше имя");
tid.setTitle("Таблица рекордов");
tid.setHeaderText("Вы побили чей-то рекорд!");
tid.setContentText("Введите ваше имя: ");
Platform.runLater(() -> tid.showAndWait());
Timers.stopTimers();
pr.setFill(Color.rgb(0,0,0,0.5));
pr.clearRect(0,0,pre.getWidth(), pre.getHeight()-50);
pr.fillRect(0,0,pre.getWidth(), pre.getHeight());
pr.setFill(Color.WHITE);
stat = "КОНЕЦ ИГРЫ!";
pr.fillText(stat, WIDTH/2-150, HEIGHT/2);
pr.fillText( "\nPOINTS: "+gamecontroller.score, WIDTH/2-170, HEIGHT/2);
gameover = true;
break;
它是这样工作的:
Platform.runLater(() ->
{
TextInputDialog tid = new TextInputDialog();
tid.setTitle("Таблица рекордов");
tid.setHeaderText("Вы побили чей-то рекорд!");
tid.setContentText("Введите ваше имя: ");
tid.showAndWait();
});
【问题讨论】:
-
“是的,我在我的应用程序中使用了三个或四个计时器。” 考虑换成
AnimationTimer/aTransition或Timeline,如果你'从这些计时器中重新修改场景。