sajjad dehghani
sajjad dehghani

Reputation: 33

How to update a stage in javafx

I expect this code that shows me a black circle in the page, then after one second it should show a white circle in the page, but it shows a blank page and after one second it shows a white circle in the page, what should I do?

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();

Upvotes: 1

Views: 1169

Answers (1)

SedJ601
SedJ601

Reputation: 13859

Remove:

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

And replace it with:

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

Upvotes: 1

Related Questions