My problem is as follows, this way I'm opening the window I have a problem using the KeyPressed function. So this way my method needs the ActionEvent parameter which when using the getSource () method, returns me the button and open the window correctly, but that's when I click the button. So for the function of the button to work inside the keyPressed function, I would have to put a parameter there as well. I tried putting new ActionEvent and (), the error some though the source is different when I press enter, which causes window n to open.
Below is the example that opens the second window by clicking the button. And lastly the KeyPressed event.
Aah, the idea is a login window, so when I enter enter do the checks and talz and open the other window. But it only works by clicking same
private void openJane (ActionEvent event) throws Exception {
Parent main_tela = FXMLLoader.load(getClass().getResource("FXMLTelaPrincipal.fxml"));
Scene main = new Scene(main_tela);
Stage st = (Stage) ((Node) event.getSource()).getScene().getWindow();
st.hide();
st.setScene(main);
st.show();
}
public void initialize(URL url, ResourceBundle rb) {
btnLogar.addEventHandler(KeyEvent.KEY_PRESSED, (KeyEvent event) -> {
try {
if (event.getCode() == KeyCode.ENTER) {
abrirJanela();
}
} catch (Exception ex) {
}
});