如何在javafx中更新一个阶段

时间:2017-04-10 18:55:51

标签: 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 个答案:

答案 0 :(得分: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();