如何打开两个Javafx窗口?
问题描述:
我正在使用javafx,希望编写一个按钮的setOnAction代码来关闭一个运行javafx2类的javafx1类,但是我看到错误'应用程序启动不能被多次调用'。我怎样才能解决这个问题?如何打开两个Javafx窗口?
//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();
}
});
答
它的完成这样的:
@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();
}
您还可以设置新窗口的坐标和大小。