This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes tracking seconds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "tracking seconds" Watch "tracking seconds" New topic

tracking seconds

Candy Bortniker
Ranch Hand

Joined: Mar 17, 2003
Posts: 123
I am writing a program for my Java class that is a GUI interface that is to count the seconds and show this on the panel. What I'm having trouble with is getting the seconds. I know how to get the seconds that it is at the time the window is opened then count from there but I want it to start at 1 or 0 every time the program begins. Where so I start to get something like this going?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Candy,
Just do the math Set it up like this:

See if that makes sense to you.
Michael Morris

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Now I'm convinced UBB definitely means U Been Bit
Candy please ignore the second smiley in the post. I would try to edit it out, but I fear the UBB god is hungry for a sacrifice and would eat the whole thing.
[ March 27, 2003: Message edited by: Michael Morris ]
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
If you have to display seconds as they go by, like a digital clock, see the Timer class. It's built for things like this, but not sure it will have accurate enough resolution to increment a counter every time it ticks. Might have to keep elapsed time.
long before = System.currentTimeInMillis();
long elapsed = System.currentTimeInMillis()-before;

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link:
subject: tracking seconds
It's not a secret anymore!