I am making a login system using javaFX. when the user enters correct username and password I want to redirect him to the "home.fxml" How can I do that, currently I am printing a message when the user enter correct data. I can seperatly create a method to link to a new scene, but when I call it in the if statement It is asking for the parameters.
package sample;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import java.io.IOException;
import java.net.URL;
import java.sql.*;
import java.util.ResourceBundle;
public class Controller {
    @FXML
    private Button cancelbutton;
    @FXML
    private Label loginmessagelabel;
    @FXML
    private PasswordField password1;
    @FXML
    private TextField username1;
    PreparedStatement pst;
    ResultSet rs;
    @FXML
    private Stage stage;
    private Scene scene;
    private Parent root;
    public void validatelogin() throws SQLException, ClassNotFoundException, IOException {
        String jdbcURL = "jdbc:mysql://localhost/medibase";
        String username = "root";
        String password = "0852";
        Connection connection = DriverManager.getConnection(jdbcURL,username,password);
        Class.forName("com.mysql.jdbc.Driver");
        String uname = username1.getText();
        String psd = password1.getText();
        pst=connection.prepareStatement("SELECT * FROM user_account WHERE username=? and password=?");
        pst.setString(1, uname);
        pst.setString(2, psd);
        rs = pst.executeQuery();
        if(rs.next()){
        loginmessagelabel.setText("Congratulations");
   
           
        } else{
            loginmessagelabel.setText("Login failed");
        }
    }
I can create a method like bellow , but when I call this in the if statement It is asking for parameters
public void switchtoHome(ActionEvent event)throws IOException {
    Parent root = FXMLLoader.load(getClass().getResource("home.fxml"));
    stage = (Stage)((Node)event.getSource()).getScene().getWindow();
    scene=new Scene(root);
    stage.setScene(scene);
    stage.show();
}
 
    