简体   繁体   English

如何在条件下打开新的 javafx fxml 窗口?

[英]How to open new javafx fxml window under if condtition?

I create a simple login form to checking username and password.我创建了一个简单的登录表单来检查用户名和密码。 I did it and my problem is while checking the username and password is correct open new fxml window.我做到了,我的问题是检查用户名和密码是否正确打开新的 fxml 窗口。 Can anyone drop some simple code to solve it.任何人都可以删除一些简单的代码来解决它。

So, below is just an example to get you started but what I usually do is I create some sort of a stage factory so that I don't have a lot of duplicate code.所以,下面只是一个让你开始的例子,但我通常做的是我创建某种舞台工厂,这样我就没有很多重复的代码。 Let me know if you have any questions.如果您有任何问题,请告诉我。

My example:我的例子:

if(/*your if condition*/){
    YourController controller = new YourController();
    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(fxmlPath));
    loader.setController(controller);
    Parent root = loader.load();
    Scene scene = new Scene(root, width, height, Color.WHITE);
    Stage stage = new Stage();
    stage.setX(xPos);
    stage.setY(yPos);
    stage.setScene(scene);
    stage.show();
}

Edit, I felt nice today but I do agree with the first comment that you received.编辑,我今天感觉很好,但我同意你收到的第一条评论。 Remember to read through the guide lines next time.下次记得通读指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM