This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Problem in updating Time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in updating Time" Watch "Problem in updating Time" New topic

Problem in updating Time

sparsh khandelwal
Ranch Hand

Joined: Dec 20, 2010
Posts: 76
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

Please Help!!!
thanks in advance
Ralph Cook
Ranch Hand

Joined: May 29, 2005
Posts: 479
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() ?

praneeth jayarathna

Joined: Jan 12, 2011
Posts: 13

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);

Praneeth J
Greg Brannon

Joined: Oct 24, 2010
Posts: 563
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.

Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
I agree. Here's the link:
subject: Problem in updating Time
It's not a secret anymore!