title: javafx Button wrapper: Provide callers with action events?
body: <p>I would like my class to be one which fires an action the same way that a button does (but I'm containing the button in my class).  I am wondering how to do this, and if this breaks Java rules to do so? </p>
  
  <p>What would I have to do to make <code>ValueButton</code> a type that one can receive action events from (when the button is clicked), and receive a reference to the <code>ValueButton</code> object which originated the event?  </p>
  
  <pre><code>import javafx.scene.control.Button;
  
  public class ValueButton {
  
      Button button;
      int val;
  
      /** Use string of value for string */
      public ValueButton(int val) {
          init(val, null);
      }
      /** Provide value and string explicity */
      public ValueButton(int val, String str) {
          init(val, str);
      }
      private void init(int val, String str) {
          this.val = val;
          if(str == null) 
              str = Integer.toString(val);
          button = new Button(str);
          button.setOnAction((ae) -&gt; {
              // I would like to pass *this* along to caller/user of ValueButton
          });
      }
  
      int getValue() { return val; }
      String getString() { return button.getText(); }
  }
  </code></pre>