2017-04-10 134 views
0

我希望这段代码能够在页面中显示一个黑色圆圈,然后在一秒钟后它应该在页面中显示一个白色圆圈,但它显示一个空白页面,一秒钟后它会显示页面中有一个白色的圆圈,我该怎么办?如何在javafx中更新舞台

Group group = new Group(); 
Scene scene = new Scene(group,200,200, Color.LIGHTGREEN); 

Circle circle = new Circle(100,100,50); 
group.getChildren().add(circle); 
stage.setScene(scene); 
stage.show(); 

Thread.sleep(1000); 
circle.setFill(Color.WHITE); 
stage.show(); 
+1

'的Thread.sleep()'块的FX应用程序线程,阻止它渲染场景。从你之前的评论看来,这不是你想要做的。你能否[编辑]你的问题来解释你*想要做的事情? –

回答

0

删除:

Thread.sleep(1000); 
circle.setFill(Color.WHITE); 

,取而代之的是:

Timeline timeline = new Timeline(new KeyFrame(Duration.millis(1000), 
      ae -> circle.setFill(Color.WHITE))); 
timeline.setCycleCount(1); 
timeline.play();