JavaFX舞台问题与隐藏和显示Ask

时间:2018-12-07 06:25:52

标签: javafx

我刚刚开始使用javafx,并且在单击按钮并打开新阶段时无法隐藏上一个阶段。这是我的代码

也可以指导我,用javafx开发软件更好吗

public void login(ActionEvent event) throws Exception
{
    try {
    Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn=DriverManager.getConnection("jdbc:sqlserver://localhost\\sqlexpress"+";databaseName=itapplication",usernametxt.getText(),passwordtxt.getText());
    Parent mainp = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
    mainpage(mainp);
    }catch (Exception e)
    {
        statuslbl.setText(e.getMessage());

    }

}
public void mainpage(Parent root) throws Exception
{
    Scene scene = new Scene(root);
    //Stage stage = new Stage();
    stage.setScene(scene);
    stage.setTitle("IT APPLICATION");
    stage.show();
}

public void addasset(ActionEvent event) throws Exception
{
    try {

        Parent asset = FXMLLoader.load(getClass().getResource("/application/Addasset.fxml"));
        mainpage(asset);
        /*Scene scene = new Scene(asset);
        addasset.setScene(scene);
        addasset.setTitle("IT APPLICATION");
        addasset.show();*/
        }catch(Exception e)
        {
            Alert alert = new Alert(AlertType.ERROR);
            alert.setTitle("Error");
            alert.setHeaderText(null);
            alert.setContentText(e.toString());
        }
}

}

1 个答案:

答案 0 :(得分:0)

Stage anyName= (Stage) (element of the stage you want to hide).getScene().getWindow();
anyName.hide();

您可以在显示新舞台后立即调用它。 如果您想了解更多,请添加评论。