java - JavaFX 任务线程显然没有同时运行
问题描述
我一直试图在场景之间放置一个加载场景,我的想法如下:
- 启动一个线程来创建所需的场景;
- 创建场景的方法也将创建的场景设置为类的Scene属性;
- 在线程运行时,正在创建和设置加载场景。
- 线程完成后,将场景设置为所需的场景。
显然,整个加载场景被忽略了,所需的场景只是简单设置。我敢打赌,线程不会同时工作。
这是任务部分和相关属性。
private Stage pokeWindow = new Stage();
private Scene currentScene;
private boolean sceneReady = false;
private String targetScene;
private int genericInt;
private final Task setGenericScene = new Task(){
@Override
protected Object call() throws Exception {
sceneReady = false;
if(targetScene.equals("summaryScene")){
setSummaryScene(genericInt);
sceneReady = true;
}
return null;
}
};
这是装载场景。
public void setLoadingScene(){
Thread loadScreen = new Thread(setGenericScene);
loadScreen.start();
if(!sceneReady){
GridPane background = new GridPane();
BackgroundImage loadingBG = new BackgroundImage(new Image((new File("src/resources/tiles/pokedexfullbg.png")).toURI().toString()), BackgroundRepeat.REPEAT, BackgroundRepeat.REPEAT, BackgroundPosition.DEFAULT, BackgroundSize.DEFAULT);
background.setBackground(new Background(loadingBG));
[...]
[more javafx code regarding the loading scene]
Scene loadingScene = new Scene(background, 512, 416);
this.pokeWindow.setScene(loadingScene);
animation1.play();
animation2.play();
animation3.play();
animation4.play();
animation5.play();
animation6.play();
animation7.play();
animation8.play();
while(!sceneReady){}
}
this.pokeWindow.setScene(currentScene);
}
解决方案
推荐阅读
- plsql - 如何使用 PLSQL 打开、读取和存储 XLSX 文件的 DB 内容?
- javascript - 更改元素尺寸与另一个元素更改的比率
- node.js - 通过 Puppeteer 设置 SessionStorage
- java - 如何让我的缓冲图像类显示在我的 GUI 中?
- php - 如何用逗号分解字符串,而不是逗号在此 («») 引号内的位置?
- python-3.x - 如何使用 flask-SqlAlchemy 检查 .all() 的值?
- javascript - 一些结果后如何停止 papaparse 流式传输
- sonarqube - 如何在 SonarQube 中删除质量配置文件
- firebase - 是否可以通过 cli 在 firebase 多站点托管中创建网站?
- python - 我遇到了这个错误的问题(-215:断言失败)!ssize.empty() in function'resize' in OpenCV