【发布时间】:2020-06-13 21:12:30
【问题描述】:
我想向用户显示他们的每秒点击次数 (CPS),因此我想将每秒显示点击次数的标签设置为 0。问题是我需要将标签设置为静态,而这不管用。这是我的代码:
public class Controller{
public Button clickButton;
public Label cpsLabel;
public Label highscoreLabel;
static int count = 0;
// static int highscoreInt = 0;
public void handleButtonClick() {
count++;
cpsLabel.setText("CPS: " + count);
}
public static void Timer() {
ScheduledExecutorService exec = Executors.newSingleThreadScheduledExecutor();
exec.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
Controller.count = 0;
cpsLabel.setText("CPS: " + count);
}
}, 0, 1, TimeUnit.SECONDS);
}
}
【问题讨论】:
-
查看
Platform::runLater函数的文档和示例。
标签: javafx timer static label runnable