home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 777 b | 42 lines |
- // Clock.java - Simple AWT clock object
- //
- // Copyright (C) 1996 by Dale Gass
- // Non-exclusive license granted to MKS, Inc.
- //
-
- import java.lang.*;
- import java.util.*;
- import java.awt.*;
- import java.net.*;
- import java.applet.*;
-
- class Clock extends Label implements Runnable {
- Thread me;
-
- // Updates the time
-
- void update() {
- Date now = new Date();
- setText(now.toString());
- }
-
- // Constructor
-
- public Clock() {
- setFont(new Font("Times Roman", Font.BOLD, 20));
- Date now = new Date();
- (me = new Thread(this)).start();
- update();
- invalidate();
- }
-
- // Dynamically update the time
-
- public void run() {
- while (true) {
- try { me.sleep(1000); } catch (Exception e) { }
- update();
- }
- }
- }
-