I am working on a program that has print time only when a function is called. I use a timer to continuously add seconds.
Timer gameTimer = new Timer ();
TimerTask time = new TimerTask() {
int sec = 0;
public void run()
{
sec++;
}
};
gameTimer.scheduleAtFixedRate(time, 1000, 1000);
However, I cannot use the sec variable outside of run (), so I can print it. I tried to place sec outside of TimerTask, but of course seC ++ will not work. Any help? Thank!
source
share