我们正在制作跳棋,我试图让新的游戏按钮重新启动应用程序,但它现在所做的就是关闭它。我们已经尝试过一些东西,但还没有深入,
@Override
public void start(Stage primaryStage) throws Exception {
Button btnNewGame = new Button("New Game");
Button btnTutorial = new Button("Tutorial");
btnTutorial.setText("Tutorial");
btnTutorial.setOnAction (new EventHandler<ActionEvent>() {
public void handle (ActionEvent event) {
if (Desktop.isDesktopSupported()) {
try {
File brukermanual = new File("Brukermanual.pdf");
Desktop.getDesktop().open(brukermanual);
} catch (IOException exception) {
}
}
}
});
btnNewGame.setOnAction( __ ->
{
System.out.println( "Restarting app!" );
primaryStage.close();
} );
primaryStage.setScene( new Scene( new BorderPane( btnNewGame ) ) );
primaryStage.show();
ToolBar toolBar = new ToolBar();
toolBar.getItems().addAll( new Separator(), btnNewGame, btnTutorial);
BorderPane pane = new BorderPane();
pane.setTop(toolBar);
pane.setCenter(createContent());
Scene scene = new Scene(pane, 640, 675);
primaryStage.setTitle("Dam spill - OBJ2000 Eksamen 2016");
primaryStage.setScene(scene);
primaryStage.show();
}
答案 0 :(得分:0)
您的括号位于错误的位置。而不是:
{{ form_end(form, {'render_rest': false}) }}
试试这个:
btnNewGame.setOnAction( __ ->
{
System.out.println( "Restarting app!" );
primaryStage.close();
} );
primaryStage.setScene( new Scene( new BorderPane( btnNewGame ) ) );
primaryStage.show();
答案 1 :(得分:0)
默认情况下,当最后打开的窗口关闭时,每个JavaFX应用程序都将被关闭。
Platform
课程中有一个方法可以改变它。[我会在我回到计算机后立即添加]
虽然在那之后它会起作用,但你真正需要清除的是你以前的数据。一种简单的方法是调用应用程序的.jar
文件。等待它使用Process.await();
打开,然后退出您的应用程序。
方式1)
1)致电stage.close();
2)以. jar
Process
申请
3)当流程开始时,退出第一个应用程序。
方式2)
清除显示用户进度条的应用程序数据。
方式3)
.......