简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM