import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.text.*;

/**
   This class implements the digital clock
   @author Sugiharto Widjaja
   @version 12/07/02
*/
public class DigitalClock extends JPanel
{
   /**
      Construct the panel
   */
   public DigitalClock()
   {
      setBackground(new Color(153,51,255));
      JPanel pane = new JPanel();
      pane.setBackground(new Color(153,51,255));
      pane.add(new ClockPanel());
      add(pane);
   }

   public static void main(String[] args)
   {
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.getContentPane().add(new DigitalClock());
      f.setTitle("Simple Digital Clock");
      f.pack();
      f.show();
   }
}

/**
   This class implements a digital clock panel
   @author Sugiharto Widjaja
   @version 12/07/02
*/
class ClockPanel extends JPanel implements Runnable
{
   /**
      Construct the panel
   */
   public ClockPanel()
   {
      setBackground(Color.red);
      field = new JTextField(10);
      field.setFont(new Font("Monotype Corsiva", Font.BOLD, 20));
      field.setBackground(Color.black);
      field.setForeground(Color.green);
      field.setEditable(false);
      df = new SimpleDateFormat("hh : mm : ss a");
      dt = new SimpleDateFormat("EEEEEEEE, MMMMMMMM dd, yyyy");
      Date now = new Date();
      field.setToolTipText(dt.format(now));
      add(field);
      t= new Thread(this);
      t.start();
   }

   /**
      The run method for the runnable object
      @throws InterruptedException
   */
   public void run()
   {
      try
      {
         while(!t.interrupted())
         {
            Date now = new Date();
            field.setText(df.format(now));
            t.sleep(1000);
         }
      }
      catch(InterruptedException e) {}
   }

   // The field to display time
   private JTextField field;
   // simple date formatter
   private SimpleDateFormat df;
   // simple date formatter
   private SimpleDateFormat dt;
   // the running thread
   private Thread t;
}