Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to show remaining time using Timer

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have created a Timer



I have to show it like

when Quiz starts it will be 00:01:00
after 1 second 00:00:59
...
00:00:01
after this it will show " Time up !"

I tried but can`t get what I wanted or I am finding hard to concentrate
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What did you try?
 
Sam Gooding
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahtab Alam wrote:I have created a Timer

Timer timer=new javax.swing.Timer(1000,new ActionListener(){ public void actionPerformed(ActionEvent e)
{
if(counter == 60) // Say Quiz time is 1 minute ( 60 seconds )
{
Quiz3.timeLabel.setText(" Time Up !");
timer.stop();
}
javax.swing.SwingUtilities.invokeLater(new updateCount());

}
}
);
timer.start();

I have to show it like

when Quiz starts it will be 00:01:00
after 1 second 00:00:59
...
00:00:01
after this it will show " Time up !"

I tried but can`t get what I wanted or I am finding hard to concentrate


Hard to say what is going on. At least in the exact code you posted, you'd have compiling errors since timer is neither a member of an enclosing class nor final ...and depending on where counter is defined, you may accidentally be resetting it to 0 each time the ActionPerformed of the Timer is executed.

I *think* this is the same example that is here:

http://www.math.uni-hamburg.de/doc/java/tutorial/uiswing/components/example-1dot4/index.html#ProgressBarDemo


But it's hard to help you since it's not clear what error your compiler or runtime is giving you...

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic