• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Regarding use of methods in Swing

 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,
I am having a swing progam. Now i want to add a method getTime() which uses Calendar class for getting time. I want to add the time in my JLabel. How can i do that. Can you send me the code snippet for achieving this. Your help is very much appreciated.

Thanks in advance,

Regards,
Raghu
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Calendar.getInstance() will give you a Calendar object with the current time and then you can use the DateFormat class to format the time anyway you like.

The JLabel has a setText method that takes a String so once you have used the DateFormat class to get the time as String, you can use the setText method to put the time in the JLabel.
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raghuraman Muthuswamy:
Dear All,
I am having a swing progam. Now i want to add a method getTime() which uses Calendar class for getting time. I want to add the time in my JLabel. How can i do that. Can you send me the code snippet for achieving this. Your help is very much appreciated.

Thanks in advance,

Regards,
Raghu



What have you tried on your own?

Layne
 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Thomas,
I have used the Calendar.getInstance() to get Hour, Minute and Seconds. I converted them to String and as per your sugesstion, used the setText method of JLabel to display the time in JLabel. Thanks for your sugesstion and will post more queries.

regards,
Raghu
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raghuraman Muthuswamy:
Dear Thomas,
I have used the Calendar.getInstance() to get Hour, Minute and Seconds. I converted them to String and as per your sugesstion, used the setText method of JLabel to display the time in JLabel. Thanks for your sugesstion and will post more queries.

regards,
Raghu



For future reference, it will help A LOT if you post some code when you ask questions. That way we can help with the specific changes you need to make. Also, if you need help resolving any compiler errors, you also need to post the full error message so we can help you.

Keep Coding!

Layne
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Raghuraman Muthuswamy:
Thanks for your sugesstion and will post more queries.



Glad I could help!

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic