java - 使用 TimeUnit 在更改 JavaFX 标签文本之间休眠
问题描述
我正在用 JavaFX 为我一直在开发的 Pokemon 游戏编写 GUI。单击要使用的动作后,我想用标签叙述攻击。我想单独显示几条消息,所以我尝试使用 TimeUnit.SECONDS.sleep() 在每条消息之间放置 3 秒的间隔。当我运行程序时,它停留在前一个屏幕(代码中的 moveOptions),等待 6 秒并重置到主屏幕(battleOptions)而不显示任何消息。为什么它不显示我的标签?
@FXML
HBox battleOptions, moveOptions, attackNarration;
@FXML
Label narration;
public void handleMoveButton() throws InterruptedException {
this.moveOptions.setVisible(false); //makes previous screen invisible
this.attackNarration.setVisible(true); //makes the layout containing my messages visible
this.narration.setText("Pikachu used Tackle");
TimeUnit.SECONDS.sleep(3); //should display above message for 3 seconds
this.narration.setText("Foe Pikachu used Tackle");
TimeUnit.SECONDS.sleep(3); //should change to this message for 3 seconds
this.attackNarration.setVisible(false); //makes message screen invisible
this.battleOptions.setVisible(true); //makes home screen visible to restart the turn
}
解决方案
推荐阅读
- openstack - OpenStack VM File System Error on reboot and nova rescue 无法拯救卷支持的实例 (HTTP 400)
- android - android pip 模式和活动导航
- bash - 针对文件按顺序运行带有 JSON 有效负载的 Curl POST
- java - Sceneform ARCore 加载并构建随机 3D 资产
- python - 使用 astropy.modeling 拟合具有负幅值的高斯问题
- sql-server - SQL Server 查询失败
- sql - 如何在 Oracle 11.g 中正确选择中间的行数?
- vb.net - 在文本文件中搜索特定文本然后阅读整行的最佳方法是什么?(视觉基础)
- python - pymunk - 是否有标准的方法来设置对象的自定义重力?
- php - 上传到 Google 云端硬盘时包含 0 个 mime 部分的无效多部分请求