• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to restrict timer from resetting to 00:00

 
arunabha dutta choudhury
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am developing an Application.It consists of a test.The starting screen shows a question with 4 answer,we hav to click the correct one.At the top there is a timer which keeps on increasing.But when we hit any answer button,it goes to the next screen & displays the next question.But the timer is reset to 00:00.Actually the control is shifted to another java file,where we call the the class that contains the timer code,ie Topmanager t = new Topmanager(),again & again,so for this reason each time we click a answer the timer starts from 00:00 again.I am giving the piece of code,can anyone help me to overcome this problem.



Timer t=new Timer();
TimerTask tt=new TimerTask() {
long startTime = System.currentTimeMillis();
public void run() {

currentTime = System.currentTimeMillis();
diff = currentTime - startTime;
min = ( diff/ 60000);
sec = ( diff%60000) / 1000;
minStr = new Long(min).toString();
secStr = new Long(sec).toString();
if (min < 10){
minStr = "0" + minStr;
}
if (sec < 10){
secStr = "0" + secStr;
}
synchronized (Application.getEventLock()) {
TimerCount.setText(String.valueOf(minStr + ":" + secStr));

}
}

};
t.scheduleAtFixedRate(tt,1, 1);

TimerCount = new LabelField("00" + ":" + "00"){
protected void paint(Graphics g) {
g.setColor(Color.WHITE);
super.paint(g);
}
};
TimerCount.setFont(myFont(16));
add(TimerCount);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic