4

我正在使用 javafx,想在按钮的“setOnAction”中编写代码来关闭 javafx1 类并运行 javafx2 类,但我看到错误“应用程序启动不能被多次调用”。我怎样才能解决这个问题?

//This code is in the class JavaFX1:
button.setOnAction(new EventHandler<ActionEvent>() {
      @Override
      public void handle(ActionEvent event) {
          JavaFX2.main(null); //How can i change current line?
          stage.close();
      }
});
4

1 回答 1

16

它是这样完成的:

        @Override
        public void handle(ActionEvent event) {
            System.out.println("Hello World!");

            Stage secondStage = new Stage();
            secondStage.setScene(new Scene(new HBox(4, new Label("Second window"))));
            secondStage.show();

        }

您还可以设置新窗口的坐标和大小。

于 2014-10-31T13:01:38.867 回答