Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Showing Sustem Time in a non-editable TextField  RSS feed

 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I m thinking to add a non-editable TextField/JTextField in my JFrame's South Panel that will show System Time in hh:mm:ss format. It will continue to show the time every second, not only the load-starting time. So i m thinking to add a thread who will create a java.util.Date object every 1 second and get its time from there and set that as a String to the JTextField. Thus would work like a clock showing current system time. But i think i m wrong in some ares as there will be other threads also and it will not happen exactly every second (will b slightly slower due to multi-threading). My question is ----
(1) Will my solution work despite the slight inaccuracy of time?
(2) Is there any better or short-cut solution in some other way?

------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Should work. Here is an example from this forum ex. Any reason why you chose JTextField over a JLabel? Is exact time a requirement? Or is this just a nice to have?
 
Ashik Uzzaman
Ranch Hand
Posts: 2373
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thnx Paul for the link! yah JLabel may be a good alternative and no exact time is not a requirement but a wishful desire....

------------------
Muhammad Ashikuzzaman (Fahim)
Sun Certified Programmer for the Java� 2 Platform
--When you learn something, learn it by heart!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!