Question
I have tried to reset the timer based on the current time after clicking a button, but it doesnt work. Help :-(
private long startTime = System.currentTimeMillis();
Timer timer = new Timer(1000, this);
timer.start();
timer.stop();
long endTime = System.currentTimeMillis();
long timeInMilliseconds = (endTime - startTime);
timer.reset();
Solution 2
The solution for my program. Thanks everyone.
public class mainClass {
private long startTime = System.currentTimeMillis();
Timer timer = new Timer(1000, this);
.....
}
public mainClass {
timer.start();
}
//Everytime the button stop clicked, the time will stop and reset to the most current time of the system
public actionPerformed () {
timer.stop();
long endTime = System.currentTimeMillis();
long timeInMilliseconds = (endTime - startTime);
**startTime = System.currentTimeMillis();** ACCEPTED
}
OTHER TIPS
My magic crystal ball says you are using a javax.swing.Timer and that there is no reset() method, it is called restart().
But then it could be wrong, it would be nice if you were a bit more explicit about what you are doing ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow