// DigitalClock class, September/October 2001
//
// Designed for Brian's Superbly Incredible and Well-Commented Non-Functional
// Clock.
//
// Objects of this class are digital clocks (that is, clocks with digits). This
// class instantiates objects of class DigitalClockFace and DigitalClockDisplay.

import aLibrary.AView;

public class DigitalClock extends Clock {
// This class, like AnalogClock, inherits from Clock, so that polymorphism can
// be used to allow one reference to refer to a DigitalClock at some times and
// an AnalogClock at others.

  /*
   * CLASS VARIABLES
   */

  private DigitalClockFace face;  // this clock's face
  private DigitalClockDisplay display;   // this clock's nifty LED display

  /*
   * CONSTRUCTOR
   */

  public DigitalClock(int x, int y, int w, int h) {
  // Creates a new DigitalClock based on (x, y, w, h) coordinates.
  //
  // Preconditions:
  //   none
  //
  // Postconditions:
  //   A new DigitalClock is created at (x, y) with width w and height h.
  //   face is instantiated and placed on this.
  //   display is instantiated and placed on this.

    super(x, y, w, h);  // call Clock constructor

    face = new DigitalClockFace(0, 0, w, h);
    face.place(this);
    // instantiate and place face

    display = new DigitalClockDisplay((int)(face.innerBounds().getX()),
                                     (int)(face.innerBounds().getY()),
                                     (int)(face.innerBounds().getWidth()),
                                     (int)(face.innerBounds().getHeight()));
    display.place(this);
    // instantiate and place display

    setDescription("digital clock");
    // a nice default description

  }

  /*
   * UPDATE METHODS
   */

  public void showTime(double time) {
  // Sets display to show time, but does not repaint. We must override this
  // method to inherit from Clock.
  //
  // Preconditions:
  //   time >= 0
  //
  // Postconditions:
  //   display is redrawn to show time.

    display.magicallyAppear(time);

  }

}
