如何打开两个Javafx窗口? [英] How to open two Javafx windows?
本文介绍了如何打开两个Javafx窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用javafx,想在按钮的'setOnAction'中编写一个代码来关闭javafx1类和运行javafx2类,但我看到错误'应用程序启动不能多次调用'。我该如何解决这个问题?
I'm using javafx, want to write a code in 'setOnAction' of a button to close a javafx1 class an run javafx2 class, but i've seen error 'Application launch must not be called more than once'. How can i fix this?
//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();
}
您还可以设置新窗口的坐标和大小。
You may also set coordinates and size of the new window.
这篇关于如何打开两个Javafx窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文