aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes How to show remaining time using Timer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to show remaining time using Timer" Watch "How to show remaining time using Timer" New topic
Author

How to show remaining time using Timer

Mahtab Alam
Ranch Hand

Joined: Mar 28, 2012
Posts: 249

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


Oracle Java Programmer , Oracle SQL Expert , Oracle Java Web Component Developer
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41524
    
  53
What did you try?


Ping & DNS - my free Android networking tools app
Sam Gooding
Ranch Hand

Joined: Dec 06, 2013
Posts: 35
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...

 
wood burning stoves
 
subject: How to show remaining time using Timer