So far I have implemented a timer in a thread which counts 6 to 0. I would like to show the progress of the java application i.e., I would like to let the user know how much time it would take for the application to run. I am looking to continuously update the time like we have a progress bar when we download a software which shows 1 minute, 59 seconds so on. I would like update the time remaining based on the time required for the program to execute rather than a predefined time frame. Thanks in advance.
public void toDisplayTime(){
TimerTask task = new TimerTask() {
int seconds = 6;
int i = 0;
@Override
public void run() {
i++;
if (i % seconds == 0) {
updateTime("Reset");
} else {
updateTime("Time left:" +(seconds - (i % seconds)));
}
}
};
Timer timer = new Timer();
timer.schedule(task, 0, 1000);
}
updateTime() is below.
public void updateTime(String updateString) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
jLabel6.setText(updateString);
}
});
}