I've searched the web for an answer and can't really make sense of them into my code. I'm still new at javafx, and coding in general.
My controller class "MainController.java" functions all my buttons, labels, text fields etc. I have created a login button which will load the Main scene on a successful login. However, as the main scene loads as a separate window, the old initial login scene still remains and I was wondering if there's an easy way to control my scenes from a controller class.
Here is my controller class bit of the code:
// Login button method call
public void Login() throws Exception {
Thread.sleep(500); // login delay
if (userInput.getText().equals("user") && passInput.getText().equals("pass")){
// load main scene
Parent root1 = FXMLLoader.load(getClass().getResource("/application/Main.fxml"));
Scene scene1 = new Scene(root1);
Stage mainScene = new Stage();
scene1.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
mainScene.setScene(scene1);
mainScene.initStyle(StageStyle.UNDECORATED);
mainScene.show();
}else {
status = "Invalid credentials";
statusLabel.setText(status);
}
}
I'm unsure of how to hide my old initial scene (the login scene). I've tried to do
loginScene.hide();
but I can't seem to link the two. I'm quite new at this so help would be appreciated. Thanks :D