-
Display of time and chaging it every secod or minute
Hi
I am learning Java and just finishing core Java. I am trying to build an
application to display time and update it every second, more or less a stop
watch . Can any one suggest me a simple solution?
Thank you
Gangadhar
-
Re: Display of time and chaging it every secod or minute
friend,
Use thread to display the time.
Now in thread, get current time.
That is all u need to do.
"Gangadhar" <gangadhararao@yahoo.com> wrote:
>
>Hi
>
>I am learning Java and just finishing core Java. I am trying to build an
>application to display time and update it every second, more or less a stop
>watch . Can any one suggest me a simple solution?
>
>Thank you
>
>Gangadhar
>
-
Re: Display of time and chaging it every secod or minute
Heres an old on screen clock example
Regards
John timney (MVP)
import java.applet.*;
import java.awt.*;
import java.util.Date;
public class mtclock extends Applet {
public void init() {
MyThread tm = new MyThread(this);
tm.start();
}
}
class MyThread extends Thread {
Date theDate;
String previousDateText = "";
String dateText;
Graphics g;
Color b, f;
public MyThread(Applet a)
g = a.getGraphics();
b = a.getBackground();
f = a.getForeground();
}
public void paint(Graphics g) {
g.setColor(b);
g.drawString(previousDateText,10,30);
g.setColor(f);
g.drawString(dateText,10,30);
previousDateText = dateText;
}
public void run() {
while (true) {
try {
theDate = new Date();
dateText = theDate.toString();
paint(g);
this.sleep(1000);
}
catch(InterruptedException e) { }
}
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks