如何在新窗口打开之前关闭窗口(JavaFX)

时间:2019-12-28 15:22:59

标签: java javafx fxml fxmlloader

public class Main extends Application {

@Override
public void start(Stage primaryStage) throws Exception{
    Parent root = FXMLLoader.load(getClass().getResource("fxml/login.fxml"));
    primaryStage.setTitle("Tester");
    primaryStage.setScene(new Scene(root, 600, 600));
    primaryStage.show();
}

public void pageLoad(String fxml_url){

    //Here I need to close the window (login.fxml)

    //Loading new fxml
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(getClass().getResource(fxml_url));

    //Checking for exception
    try {
        loader.load();
    } catch (IOException e) {
        e.printStackTrace();
    }
    //Setting parameters
    Parent root = loader.getRoot();
    Stage stage = new Stage();
    stage.setScene(new Scene(root));
    stage.setResizable(false);
    stage.setTitle("Tester");
    stage.show();
    //Icon
    //Image icon = new Image(getClass().getResourceAsStream("icon/cross.png"));
    //stage.getIcons().add(icon);
}

public static void main(String[] args) throws  Exception{
        launch(args);
}

这里有一段代码,其中pageLoad()允许创建新页面。那么如何在pageLoad()开始之前关闭页面?还是如何在窗口之间更有效地进行交互(替代解决方案)?

0 个答案:

没有答案
相关问题