Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to implement a really custom event handler that can handle any EventType in JavaFX?
    text
    copied!<p>I am planning to create a single EventHandler Class that will handle all Types of events for all my controls in my JavaFX class. </p> <p>For example, I added my custom event handler class to handle the Action Event the following way and it just works fine: </p> <pre><code>userNameText.addEventHandler(ActionEvent.ACTION, new DataChangeHandler()); cmbBox.addEventHandler(ActionEvent.ACTION, new DataChangeHandler()); btn.addEventHandler(ActionEvent.ACTION, new DataChangeHandler()); </code></pre> <p>Here is my custome event handler class code:</p> <pre><code>public class DataChangeHandler implements EventHandler&lt;ActionEvent&gt; { public void handle(ActionEvent event) { System.out.println("My Very Own Private Button Handler"); } } </code></pre> <p>But when I try to change one of the addEventHandlers to MouseEvent and modify the main EventHandler class the following way, it shows an error "The Interface eventhandler cannot be implemented more than once with different arguements":</p> <pre><code>userNameText.addEventHandler(ActionEvent.ACTION, new DataChangeHandler()); cmbBox.addEventHandler(MouseEvent.CLICKED, new DataChangeHandler()); btn.addEventHandler(ActionEvent.ACTION, new DataChangeHandler()); public class DataChangeHandler implements EventHandler&lt;ActionEvent&gt;, EventHandler&lt;MouseEvent&gt; { public void handle(ActionEvent event) { System.out.println("My Very Own Private Button Handler - ACTIONEVENT"); } @Override public void handle(MouseEvent arg0) { System.out.println("My Very Own Private Button Handler - MOUSEEVENT"); } } </code></pre> <p>Is there any other way to achieve this? Please help. Thanks in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload