我正在尝试在使用 JavaFX(IDE:NetBeans)和操作系统(Win 10)开发的屏幕录制应用程序中添加计时器。我现在添加一个计时器,它将用作:
用户单击开始录制,我的应用程序上的标签应开始显示时间为 00:00:00,我的时间以秒为单位,即使在控制台上打印,但当我使用它显示在应用程序上时只显示 0 秒。我也附上代码。请帮忙。当我有值时,如何刷新应用程序界面或运行计时器,它只是不更新。
在这里你可以看到我的应用程序没有启动计时器;但是,正在控制台上打印 App's Snap Console Snap
private void scheduleTimerTasks() {
isRecording = true;
int delay =50;
long period = 500;
//1000 / 48;
RecordTimer.reset();
timerRecord = new Timer("Thread TimerRecord");
timerCount = new Timer("Thread TimerCount");
recorderTask = new ScreenRecorderTask(encoder, rectangle);
countTask = new TimerCountTask(Timer);
timerRecord.scheduleAtFixedRate(recorderTask, delay, period);
timerCount.scheduleAtFixedRate(countTask, delay, period);
Timer.setText(""+countTask.timeInSec+" s"); //Setting Label Text
System.out.println(countTask.timeInSec);
recordStateLabel.setText("recorder Started...");
}
最佳答案
您可以使用javafx.animation.animationTimer中的AnimationTimer,该计时器的handle方法将在每一帧被调用。
关于java - JavaFX 1.8 中的计时器(时钟),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57165996/