title: How to set a method to a JavaFX Alert Button
body: <p>I want to give the buttons "OK" and "Cancel" a method, which will be execute, when the user clicks on one of these buttons:</p>
  
  <p><a href="https://i.stack.imgur.com/yNApy.png" rel="noreferrer"><img src="https://i.stack.imgur.com/yNApy.png" alt="Alert Box"></a></p>
  
  <p>How can I do this with my code?</p>
  
  <pre><code>Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
  alert.setTitle("Test");
  alert.setHeaderText("This is a test.");
  alert.setResizable(false);
  alert.setContentText("Select okay or cancel this alert.");
  alert.showAndWait();
  </code></pre>
  
  <p>In my theory, the code to set an action for one of the buttons looks like this:</p>
  
  <pre><code>alert.setActionForButtonOK(OkMethod());
  </code></pre>