title: How to pause Java.uti.Timer?
body: <p>I am developing a JavaFX application where I am using <code>java.util.Timer</code> to track user mouse movement.</p>
  
  <p>The concept is If the mouse doesn't move for some seconds in the scene then the buttons will be invisible whenever the mouse moves button will appear again. And whenever user put the cursor over a button timer will be stopped.And when exit the button timer will start again.</p>
  
  <p>This is the start timer method</p>
  
  <pre><code>    public static void startTimer(){
  
      timer = new Timer();
      task = new TimerTask() {
  
          @Override
          public void run() {
  
              if(detection&gt;0){
                  Util_Class.getUi_obj().getLeftbuttongroup().setVisible(false);
                  Util_Class.getUi_obj().getRightbuttongroup().setVisible(false);
              }else{
                  detection++;
              }
  
          }
      };
  
      timer.schedule(task, 2000, 2000);
      System.out.println("TIMER STARTED");
      //startTimer();
  }
  </code></pre>
  
  <p>This is to stop the timer</p>
  
  <pre><code>public static void stopTimer(){
  
      timer.cancel();
      System.out.println("TIMER STOPED");
  }
  
  
  
  public void leftbuttonmovehandler(MouseEvent event){
  
  
      if(event.getEventType()==MouseEvent.MOUSE_ENTERED){
          System.out.println("MOUSE ENTERED");
          Main.stopTimer();
      }else if(event.getEventType()==MouseEvent.MOUSE_EXITED){
          System.out.println("MOUSE EXITED");
          Main.start();
      }
  
  }
  </code></pre>
  
  <p>Now my code works fine at first whenever the app starts but when i reload the app the callback functions triggers as expected but the buttons disappear despite the cursor is on the button.</p>
  
  <p>It would be great if someone helps me. </p>