wood burning stoves 2.0*
The moose likes Java in General and the fly likes Regarding use of methods in Swing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding use of methods in Swing" Watch "Regarding use of methods in Swing" New topic
Author

Regarding use of methods in Swing

Raghuraman Muthuswamy
Ranch Hand

Joined: Mar 18, 2003
Posts: 73
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
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Raghuraman Muthuswamy
Ranch Hand

Joined: Mar 18, 2003
Posts: 73
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

Joined: Dec 06, 2001
Posts: 3061
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
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Raghuraman Muthuswamy:
Thanks for your sugesstion and will post more queries.


Glad I could help!

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Regarding use of methods in Swing
 
Similar Threads
how to create a Calendar
Can I use Tapestry framework in Swing (desktop) applications?
Passed SCEA part 2 and 3 with 95 % ����
how to add image to swing, i dont need the code?
Date and Time using swing