title: Create a method for a long click or pressed Button in javafx
body: <p>In my program I need to make an action when a button is long pressed/click. So I decided to create a method which gets the button in its parameters and return a boolean when the button click is longer than 1 second :</p>
  
  <pre><code>public class EventOperations {
  
  JFXButton button;
  boolean result = false;
  
  // Button long click
  public EventOperations(JFXButton btn) {
      button = btn;
  }
  
  public void isLongPressed() {
  
      final AnimationTimer timer = new AnimationTimer() {
  
      private long lastUpdate = 0;
  
      @Override
      public void handle(long time) {
          if (this.lastUpdate &gt; 2000000000) {
              result = true;
              System.out.println("PRESSED !!!!!!!!!");
          }
          this.lastUpdate = time;
      }
      };
  
      button.addEventFilter(MouseEvent.ANY, new EventHandler&lt;MouseEvent&gt;() {
  
          @Override
          public void handle(MouseEvent event) {
              if (event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
                  timer.start();
              } else {
                  timer.stop();
              }
          }
      });
  
  }
  
  public boolean getIsPressed() {
      return result;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>MAIN.JAVA</p>
  
  <pre><code>EventOperations buttonPressed = new EventOperations(jfxButtonFolder);
  buttonPressed.isLongPressed();
  </code></pre>
  
  <p>But everytime I clicked quickly on the button it shows several "PRESSED !!!" so it doesn't work. The number of 2000000000 is an example.
  <strong>What can I do to get the boolean in my main java method and if it's "pressed" call a function to do something ?</strong></p>
  
  <p><strong>EDIT ! It's work perfectly thank you !</strong></p>