title: How to set an instance of the EventHandler interface as the action for a button
body: <p>I am trying to set the action of a button by passing an instance of the <code>EventHandler&lt;&gt;</code> interface to its <code>setOnAction()</code> method, however it is not working.</p>
  <p><strong>Class 1:</strong></p>
  <pre class="lang-java prettyprint-override"><code>public class Class1 {
         
     private Class2 class2;
     private Button buttonDelete = null;
  
     private Button getButtonDelete() {
         if (buttonDelete == null) {
             buttonDelete = new Button(&quot;Delete&quot;);
             buttonDelete.setOnAction(class2);
         }
         return buttonDelete;
     }
  }
  </code></pre>
  <p><strong>Class 2:</strong></p>
  <pre class="lang-java prettyprint-override"><code>public class Class2 implements EventHandler&lt;ActionEvent&gt; {
      @Override
      public void handle(ActionEvent event) {
          // do something
      }
  }
  </code></pre>