ActionEvent get source of button JavaFX
<p>I have about 10 buttons which are going to be sent to the same method. I want the method to identify the source. So the method knows button "done" has evoked this function. Then I can add a switch case of if statement to handle them accordingly. This is what I have tried </p>

<pre><code>//Call:
    btnDone.setOnAction(e -&gt; test(e));


   public void test(ActionEvent e) {
        System.out.println("Action 1: " + e.getTarget());
        System.out.println("Action 2: " + e.getSource());
        System.out.println("Action 3: " + e.getEventType());
        System.out.println("Action 4: " + e.getClass());
    }
</code></pre>

<p>Output Result:</p>

<pre><code>Action 1: Button@27099741[styleClass=button]'Done'
Action 2: Button@27099741[styleClass=button]'Done'
Action 3: ACTION
Action 4: class javafx.event.ActionEvent
</code></pre>

<p>Done is the text on the button. As you can see I could use  <code>e.getTarget()</code> and/or <code>e.getSource()</code> then I'll have to substring it, so only the "Done" appears. Is there any other way to get the string in the apostrophe instead of having to substring. </p>

<blockquote>
  <p>UPDATE: I have tried passing Button and it works but I still want to
  know a solution using ActionEvent.</p>
</blockquote>

<pre><code>//Call:
        btnDone.setOnAction(e -&gt; test(btnDone));


       public void test(Button e) {
            System.out.println("Action 1: " + e.getText());
        }
</code></pre>

<p>Output is <code>Action 1: Done</code></p>