您已经注意到您无法再次执行启动过程。因此,最好的选择是重写应用程序类,并将初始化逻辑移至新方法:
void cleanup() { // stop animations reset model ect.}void startGame(Stage stage) { // initialisation from start method goes here btnNewGame.setonAction(e -> { restart(stage); }); stage.show();}void restart(Stage stage) { cleanup(); startGame(stage);}@Overridepublic void start(Stage primaryStage) { startGame(primaryStage);}笔记
- 根据更改的场景部分,更改某些节点的状态可能已足够(比创建新场景更有效)。(只需看看您在游戏中所做的更改,然后自己决定)
launch()
是一种static
方法,因此您不应该自己创建应用程序类的实例。使用Application.launch(GameUI.class, args);
代替,让该方法处理GameUI
实例的创建。- 将UI创建移动到与应用程序类不同的类可能是更好的设计。这种方式的代码重用更加容易,因为它不需要创建的子类的实例
Application
。



