I'm creating a JavaFX application. After the login screen I want the user to see a slightly different layout if he's also administrator.
How do I change the view of the MainWindow
right after the LoginWindow
according to this?
(I tried to lighten the code as much as I could)
Here's the code of the LoginController.java
class, (among the other things) responsible of localizing admin users:
public class LoginController {
// All @FXMLs needed ...
@FXML
private Button loginButton;
public void initialize() {
loginButton.setOnAction(event -> {
if (authorize()) {
MainLoader mainLoader = new MainLoader();
mainLoader.loadMain();
// Close login screen
}
});
private boolean authorize() {
// returns true if the user is authorized
}
private boolean isAdmin() {
// returns true if the user is also admin
}
}
As you can see, LoginController
calls MainLoader.java
:
public class MainLoader {
public void loadMain() {
try {
Parent root = FXMLLoader.load(getClass().getResource("../../view/main_screen.fxml"));
Stage stage = new Stage();
stage.setScene(new Scene(root));
stage.show();
} catch (IOException ex) {
// Manage exception
}
}
}
Here's the code of the MainController.java
class, responsible of setting up correctly the Main window of my application:
public class MainController {
// All @FXMLs needed ...
@FXML
private Tab adminTab;
public void initialize() {
// Setting all controls of previous widgets...
// IF IS ADMIN THEN:
adminTab.setDisable(false);
}
}