File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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: 172

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


Mahtab Alam (OCJP )
Blogs : alamsql.blogspot.in , alammahtab.blogspot.in
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
What did you try?


Ping & DNS - updated with new look and Ping home screen widget
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...

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to show remaining time using Timer
 
Similar Threads
back ground process id ??
SimpleDateFormatter shows wrong hour?
Calendar() / Date() bug ???
Assign variables to a Calendar
How to convert hours,minutes,seconds to seconds