简体   繁体   English

我的JavaFX计时器不起作用。 为什么?

[英]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. 然后,一旦单击按钮,我将调用timer.play()

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 输出保持在0.0且不变

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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