mark devan
mark devan

Reputation: 7

My timer for JavaFX isn't working. Why?

I'm trying to only start the time if the user clicks a button. Then I would call timer.play() once the button is clicked.

I can't understand why my timer isn't working. It prints

timer = new Timeline(new KeyFrame(Duration.millis(1000), new EventHandler<ActionEvent>() {
    public void handle(ActionEvent event) {
        countTimerSecs++;
    }
)});
timer.setCycleCount(Timeline.INDEFINITE);

This line of code is in a big function, so I only put that part of it.

timerTextField.setText(String.ValueOf(countTimerSecs));

The output stays at 0.0 and doesn't change

Upvotes: 0

Views: 140

Answers (1)

Michael
Michael

Reputation: 44090

timer = new Timeline(new KeyFrame(Duration.millis(1000), new EventHandler<ActionEvent>() {
    public void handle(ActionEvent event) {
        timerTextField.setText(String.ValueOf(++countTimerSecs));
    }
)});
timer.setCycleCount(Timeline.INDEFINITE);

Upvotes: 2

Related Questions