I am working on my project where I have UI where the user has to enter his username and password in the text fields in the login stage, which moves him to the next stage where I want to know which user is currently logged in. Both stages have separate controllers. I tried to make the setter and getter in the login stage where I set the user to the username he enters in the username text field and get it from the next stage.
Simplified login Screen:
private String currentUser;
public void setCurrentUser(String currentUser)
    {
        this.currentUser = currentUser;
    }
    public String getCurrentUser()
    {
        return currentUser;
    }
public void validateLogin() {
        DatabaseConnection connectNow = new DatabaseConnection();
        Connection connectDB = connectNow.getConnection();
        String verifyLogin = "SELECT count(1) FROM table WHERE username = '" + usernameTextField.getText() + "' AND password = '" + enterPasswordField.getText() + "'";
        
         try {
            Statement statement = connectDB.createStatement();
            ResultSet queryResult = statement.executeQuery(verifyLogin);
            while (queryResult.next()) {
                if (queryResult.getInt(1) == 1) {
                    setCurrentUser(usernameTextField.getText());
                    openScreen();
                } else {
                    loginMessageLabel.setText("No such user");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            e.getCause();
        }
When I run this method in the stage I get in after successful login in, it returns null:
System.out.println(userController.getCurrentUser());
Is there any way to make it work this way? Sorry for a poor explanation, hope u get what I meant
 
     
    