home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in231vfd / clock.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  777 b   |  42 lines

  1. //    Clock.java - Simple AWT clock object
  2. //
  3. //    Copyright (C) 1996 by Dale Gass
  4. //    Non-exclusive license granted to MKS, Inc.
  5. //
  6.  
  7. import java.lang.*;
  8. import java.util.*;
  9. import java.awt.*;
  10. import java.net.*;
  11. import java.applet.*;
  12.  
  13. class Clock extends Label implements Runnable {
  14.     Thread me;
  15.  
  16.     // Updates the time
  17.  
  18.     void update() {
  19.     Date now = new Date();
  20.     setText(now.toString());
  21.     }
  22.  
  23.     // Constructor
  24.  
  25.     public Clock() {
  26.     setFont(new Font("Times Roman", Font.BOLD, 20));
  27.     Date now = new Date();
  28.     (me = new Thread(this)).start();
  29.     update();
  30.     invalidate();
  31.     }
  32.  
  33.     // Dynamically update the time
  34.  
  35.     public void run() {
  36.     while (true) {
  37.         try { me.sleep(1000); } catch (Exception e) { }
  38.         update();
  39.         }
  40.     }
  41. }
  42.