I want the clock to show the current time and be updated every second. The code I'm using is:
int timeDelay = 1000;
ActionListener time;
time = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
timeLabel.setText(DateTimeUtil.getTime());
}
};
SwingWorker timeWorker = new SwingWorker() {
@Override
protected Object doInBackground() throws Exception {
new Timer(timeDelay, time).start();
return null;
}
};
timeWorker.execute();
That I want to update the text timeLabelin a different thread than EDT.
Am I doing it right? Any other better way?
In addition, for information I added timeLabelto extended JPanel, which contains several similar types of utilities and is called in another Main JFrame.
source
share