| Author |
Problem in updating Time
|
sparsh khandelwal
Ranch Hand
Joined: Dec 20, 2010
Posts: 68
|
|
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: 530
|
|
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.
|
Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
|
 |
 |
|
|
subject: Problem in updating Time
|
|
|