title: How exit from a timeline in javafx?
body: <p>i have this code</p>
  
  <pre><code>private static int seconds = 0 ;
  
          public void start(Stage stage) throws IOException{
         //some code
        //then add a timer because i want to change this stage's scene after 7 seconds
         final Timeline timeline = new Timeline(new KeyFrame(Duration.ZERO, new EventHandler() {
              @Override public void handle(Event event) {
  
                 seconds++
                 if(seconds&gt;=7){
  
                     AnotherScene mainmenu = new AnotherScene ();
                     try {
                         AnotherScene .startScene(stage);
  //i have startScene methode in AnotherScene  classthat give this stage and load another fxml file
                     } catch (IOException ex) {
                         Logger.getLogger(startUpScene.class.getName()).log(Level.SEVERE, null, ex);
                     }
                 }
              }
               }),  
              new KeyFrame(Duration.seconds(1.0)));
              timeline.setCycleCount(Timeline.INDEFINITE);
              timeline.play();//start timer
  //some code
  stage.show();
  }
  </code></pre>
  
  <p>i can change scene of my stage but i have a problem i see this timer works for my AnotherScene because i add a static int 'a' in AnotherScene and print 'a' in AnotherSceneController and see every seconds print this integer any ideas for exiting from timer ? thanks</p>
  
  <p>Edit:</p>
  
  <p>i change <code>timeline.setCycleCount(Timeline.INDEFINITE);</code> to <code>timeline.setCycleCount(8);</code> and my problem solved but any better Ideas?</p>