2013-06-26 31 views
0
Timeline addRandomPeopleFrequently = new Timeline(new KeyFrame(Duration.millis(20), new EventHandler<ActionEvent>() { 
      @Override 
      public void handle(ActionEvent event) { 
       if(table.getItems().size()==0) 
       { 

        try { 
         stop(); 
        } catch (Exception e1) { 
         // TODO Auto-generated catch block 
         e1.printStackTrace(); 
        } 
       } 
       int index = RNG.nextInt(table.getItems().size()); 
       count++; 
       table.getItems().remove(index); 
       e=System.currentTimeMillis() -s; 
      } 
      })); 

      addRandomPeopleFrequently.setCycleCount(Animation.INDEFINITE); 
      addRandomPeopleFrequently.play(); 

我有這樣的代碼,我想停止時間軸時,我的表的大小變爲0 此代碼是工作任何sugegstion做停止的JavaFX時間軸當表的大小變爲零

回答

0

你停止

javafx.​application.​Application.stop(); 

它什麼都不做,而是做

addRandomPeopleFrequently.stop(); 
+0

如果你嘗試過,你會得到編譯器錯誤'addRandomPeopleFrequently可能沒有被初始化' – ajeh

+0

@ajeh我沒有提供細節,但該事件處理程序應該在addRandomPeopleFrequently初始化後單獨定義和啓動。 –

+0

類似的時間線只適用於我,如果addRandomPeopleFrequently是一個在構造函數中創建的類字段,因爲匿名類實例只能使用最終的局部變量。 – ajeh