This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in updating Time

 
sparsh khandelwal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Everybody
i try to display the running time,but it just show the present time and not update the time although i use multi threading in my program.
Program part look likes:-

Even when i put the code common to both in run method it not works for me
i.e

Please Help!!!
thanks in advance
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming this is in Swing, you cannot reliably update a Swing GUI from outside the UI thread, no matter how many other threads you use. Perhaps you need to put it into something run by java.awt.EventQueue.invokeLater() ?

http://www.javamex.com/tutorials/threads/invokelater.shtml

rc
 
praneeth jayarathna
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi try this code fragment,


//import java.util.Date;

Date date=new Date();

String ss=String.valueOf(date);
String d=(ss.split(" ")[5]);
String d1=(ss.split(" ")[2]);
int d2=(date.getMonth()+1);
System.out.println(d+d1+d2);


Praneeth J
(PCJT)
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might find this discussion useful:

Fred Swartz' Text Clock

I refer to Fred's notes a lot when I need grounding to Java basics.

Edit: My apologies to Mr. Fred Swartz. For some reason, I had the wrong first name stuck in my head.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic