我试图每隔几秒钟更新一次标签,我尝试使用普通的Timer,但由于它在另一个线程中无法更改标签,因此这是Timer:
public void setTimer(Timer timer, int seconds, String userName, String content, VBox tabContent,ArrayList<Integer> countTweetsArray, Label statusLabel) {
TabContent tabContentObj = new TabContent();
timer.schedule(new TimerTask() {
@Override
public void run() {
setTweet(userName, content);
//tabContentObj.createStatusScreen(tabContent, countTweetsArray, remainingTweets);
System.out.println(content+" after "+seconds);
System.out.println("countTweetsArray: "+countTweetsArray.get(0));
statusLabel.setText(countTweetsArray.get(0).toString());
countTweetsArray.set(0, (countTweetsArray.get(0)+1));
tabContentObj.timersMap.put(userName, timer);
}
}, (seconds*1000));
}
Run Code Online (Sandbox Code Playgroud)
我读到可以使用TimeLine定期更改标签,但是我无法理解它如何工作键值和关键帧。有没有一种方法可以触发不包含任何动画的void方法?