I'm trying to write a custom eventhandler based on the alert that my application creates when you press a button. This is what I'm trying to extract (see below).
view.getStart().setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
alert.setHeaderText("This will reset the game.");
alert.setContentText("Are you sure?");
alert.setTitle("Warning");
alert.getButtonTypes().clear();
ButtonType no = new ButtonType("No");
ButtonType yes = new ButtonType("Yes");
alert.getButtonTypes().addAll(no, yes);
alert.showAndWait();
if (alert.getResult() == null || alert.getResult().equals(no)) {
event.consume();
}
if (alert.getResult().equals(yes)) {
view.getTextField();
view.getScene().getWindow().hide();
}
}
});
I know how to make the handler a standalone class and then use that instead of new EventHandler, but I've no idea how to get the variables: alert.getResult(), alert.getButtonType() & alert.getEvent.consume();
Note: I'm working with model view presenter and this is currently in my view class.