animation - showAndWait() 与动画,使用 Platform.runlater() 给出不同的行为
问题描述
当我不使用动画并且拥有 stage.showAndWait() 时,它会执行正确的行为(单击“是”按钮时,我会从方法中得到正确的结果)但是我想使用动画,因此我使用了解决方法
Platform.runLater(()-> {
stage.setScene(new Scene(root));
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
}
但这一次,即使在单击任何按钮之前,该值也是错误的,并且我没有从该按钮中获得任何价值。
所以这是我显示确认对话框的方法。如果单击是按钮,我想重新启动游戏,如果没有,则退出程序。
public boolean display(String title, String message) throws IOException {
FXMLLoader confirmViewLoader = new FXMLLoader(getClass().getResource("../main/ConfirmDialogBoxView.fxml"));
confirmViewLoader.load();
ConfirmDialogBoxController confirmDialogBoxController = confirmViewLoader.getController();
confirmDialogBoxController.setConfirmLabelText(message);
Parent root = confirmViewLoader.getRoot();
Stage stage = new Stage();
stage.setTitle(title);
Platform.runLater(()-> {
stage.setScene(new Scene(root));
stage.initModality(Modality.APPLICATION_MODAL);
stage.showAndWait();
}
);
return confirmDialogBoxController.getBtnChoice();
}
这里是检查游戏是否结束的部分
...
TranslateTransition animation = new TranslateTransition(Duration.seconds(0.25), disc); ///// Animation
animation.setToY(row * (TILE_SIZE + 5) + TILE_SIZE / 4);
if (checkConnections(column, currentRow)) {
gameOver();
}else{
playerRed = !playerRed;
}
animation.play();
}
在我的确认对话框控制器中:
public boolean getBtnChoice(){
return answer;
}
@FXML
public void yesButtonClicked(ActionEvent actionEvent) {
answer = true;
stage = (Stage) yesButton.getScene().getWindow();
stage.close();
}
@FXML
public void noButtonClicked(ActionEvent actionEvent) {
answer = false;
Stage confirmWindow = (Stage) noButton.getScene().getWindow();
confirmWindow.close();
Platform.exit();
}
解决方案
推荐阅读
- python - 在使用 Python 3 中的变量更新 sqlite 中的列名时遇到问题
- laravel - 我们可以通过锚标签中刀片的 route() 方法传递 PUT、PATCH 和 DELETE 请求吗?
- java - REST 组件的类似 EJB 的通信
- ios - SWIFT - JSON 错误:无法读取数据,因为它的格式不正确
- image - .tga 图像:应该由一个单词表示的值只有在我阅读前半个单词时才是正确的
- mysql - 在聚合的 sql 语句中插入 where 条件
- c# - ssis用什么上传到firebird
- apache-spark - Spark 1.6 框架太大 17882426381
- node.js - pm2 watch 参数不监视文件
- php - 在子目录中创建特定文件列表