Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tracking seconds

 
Candy Bortniker
Ranch Hand
Posts: 123
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Candy,
Just do the math Set it up like this:

See if that makes sense to you.
Michael Morris
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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;
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic