File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding use of methods in Swing

 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Ranch Hand
Posts: 13974
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic