I created a login screen that when authenticating redirects to the menu, but making the call by the controller does not work.
Main:
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("view/Login.fxml"));
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
LoginController:
@FXML
void logar(ActionEvent event) throws IOException {
if (LoginDao.autenticar(text_usuario.getText(), text_senha.getText())) {
Parent blah = FXMLLoader.load(getClass().getResource("view/Menu.fxml"));
Scene scene = new Scene(blah);
Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
appStage.setScene(scene);
appStage.show();
} else {
System.out.println("login ou senha incorretos");
}
}
Have I tried to instantiate Main in the controller to access primaryStage and nothing, how could I perform this screen switching? alias I started to move today with javaFX would this be the most practical?