【问题标题】:How to open two Javafx windows?如何打开两个 Javafx 窗口?
【发布时间】:2014-10-31 12:16:02
【问题描述】:

我正在使用 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();
      }
});

【问题讨论】:

    标签: javafx launch application-error


    【解决方案1】:

    这样做是这样的:

            @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();
    
            }
    

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

    【讨论】:

      猜你喜欢
      • 2013-02-09
      • 1970-01-01
      • 2014-10-19
      • 2021-06-30
      • 2013-09-18
      • 2018-11-17
      • 2015-07-15
      • 2017-08-26
      • 2016-09-23
      相关资源
      最近更新 更多