Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,107 members, 7,807,339 topics. Date: Wednesday, 24 April 2024 at 12:30 PM

How Can I Add A Time Stamp To My Gui - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / How Can I Add A Time Stamp To My Gui (1096 Views)

Join The Clarion Call: Seun, Add A 'dislike' Button To Every Topic Or Post / Hope For C++ Newbies: Gui Toolkits / How To Create A Simple Calculator Using Java Programing Language GUI (2) (3) (4)

(1) (Reply) (Go Down)

How Can I Add A Time Stamp To My Gui by Danyl(m): 7:34pm On Jan 23, 2013
Good day gr8 programmers,i want to add a time stamp that updates itself every seconds on my GUI,actually its an applictn that nids users to perform a task within a specified time limit. I want it to be smthn like ds Time: 00:00:00, the first set of zeros is the hour, next minute and nxt seconds, while d seconds start countn,it gets to 60, the minute increments every 60 seconds. I understand ds is a threadn issue n I've tried implementing the runnable interfc bt its not working as intended...am working ds desktop on netbeans so my codes may not luk gud but if any1 can help a simple code snippet will be enough. Thank you
Re: How Can I Add A Time Stamp To My Gui by Shimao(m): 12:21am On Jan 24, 2013
Your task is made up of 2 parts; a way to execute a recurrent activity and a way to format and update a display.

For the 1st part you have 2 options. You could implement the Runnable interface where you set up a loop bounded by the total time limit in seconds and have the thread sleep repeatedly for 1 second only to wake up each time to update a time spent counter and update the display. You may need to write formatting code to convert the time spent in seconds to desired representational string then update a JLabel. Remember, you need to execute the update on the event dispatch thread since you will be on a separate thread. Use javax.swing.SwingUtilities.invokeLater to schedule the update on the event dispatch thread.

Alternatively, you could look at the javax.swing.Timer class which allows you execute recurrent activities at predefined intervals. All you need to do is specify a time interval and implement and register an ActionListener to receive time expiration events and perform updates on the time spent counter and display as above but without the hassles of ensuring thread safety as the class is already thread safe.

You should go with option 2.
Re: How Can I Add A Time Stamp To My Gui by Danyl(m): 9:52am On Jan 24, 2013
Thanks shimao,i'll luk into d second option,n return 2gv an update.
Re: How Can I Add A Time Stamp To My Gui by xterra2(m): 11:48pm On Jan 28, 2013
gregorian calendar is what you need to use
Read about the class - the solution of your problem lies there
Re: How Can I Add A Time Stamp To My Gui by Danyl(m): 7:12am On Jan 30, 2013
@shimao, the problem's solved. Thanks
@xterra2, it's bn solved

(1) (Reply)

Inspiring Your World!! Facepassion. / New! Hot! More Than 15 GB Master Resell Rights Products! / Mobile Bulk Sms Application

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.