aspose file tools*
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem in updating Time" Watch "Problem in updating Time" New topic
Author

Problem in updating Time

sparsh khandelwal
Ranch Hand

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

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() ?

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

rc
praneeth jayarathna
Greenhorn

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);
System.out.println(d+d1+d2);


Praneeth J
(PCJT)
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 560
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: http://aspose.com/file-tools
 
subject: Problem in updating Time