有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java在同一阶段内切换场景

我一直在网上冲浪,还没有找到任何与我当前的设置/代码相关的东西

所以我可能只是做错了什么,但我现在得到的是:

Parent dashboardParent = FXMLLoader.load(getClass().getResource("dashboard.fxml"));
        Scene dashboardScene = new Scene(dashboardParent);
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(dashboardScene);
        window.show();
        System.out.println("Success");

我尝试过许多类似的方法,似乎对其他人有用,所以如果有人能帮助我,我将不胜感激

当它打印出成功的信息时,它肯定走到了这一步

简而言之,我有我的登录页面,当用户登录时,我希望它改变场景,显示仪表板

编辑:

方法是:

private void clickLogin(MouseEvent event) throws SQLException, IOException {     
    String query1 = "SELECT * FROM users WHERE (username  = ? OR email = ?) AND password = ?";
    con = handler.getConnection();
    pst = con.prepareStatement(query1);
    pst.setString(1, usernameField.getText());
    pst.setString(2, usernameField.getText());
    pst.setString(3, passwordField.getText());

    ResultSet rs = pst.executeQuery();

    if(!rs.isBeforeFirst()){
        System.out.println("Failed.");
    } else {  

        Parent dashboardParent = FXMLLoader.load(getClass().getResource("dashboard.fxml"));
        Scene dashboardScene = new Scene(dashboardParent);
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(dashboardScene);
        window.show();
        System.out.println("Success");

    }

我注释掉了以下几行:

同时使用//和/**/

private void clickLogin(MouseEvent event) throws SQLException, IOException {     
    //String query1 = "SELECT * FROM users WHERE (username  = ? OR email = ?) AND password = ?";
    //con = handler.getConnection();
    //pst = con.prepareStatement(query1);
    //pst.setString(1, usernameField.getText());
   // pst.setString(2, usernameField.getText());
   // pst.setString(3, passwordField.getText());

   // ResultSet rs = pst.executeQuery();


        Parent dashboardParent = FXMLLoader.load(getClass().getResource("dashboard.fxml"));
        Scene dashboardScene = new Scene(dashboardParent);
        Stage window = (Stage)((Node)event.getSource()).getScene().getWindow();
        window.setScene(dashboardScene);
        window.show();
    //if(!rs.isBeforeFirst()){
   //     System.out.println("Failed.");
   // } else {  
   //     System.out.println("Success");
   //     
   // }
}

它仍在调用if/else方法并显示结果。。。这怎么可能


共 (0) 个答案