Class ClockDisplay


  • public class ClockDisplay
    extends java.lang.Object
    The ClockDisplay class implements a digital clock display for a European-style 24 hour clock. The clock shows hours and minutes. The range of the clock is 00:00 (midnight) to 23:59 (one minute before midnight). The clock display receives "ticks" (via the timeTick method) every minute and reacts by incrementing the display. This is done in the usual clock fashion: the hour increments when the minutes roll over to zero.
    Version:
    2016.02.29
    Author:
    Michael Kölling and David J. Barnes
    • Constructor Summary

      Constructors 
      Constructor Description
      ClockDisplay()
      Constructor for ClockDisplay objects.
      ClockDisplay​(int hour, int minute)
      Constructor for ClockDisplay objects.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getTime()
      Return the current time of this display in the format HH:MM.
      void setTime​(int hour, int minute)
      Set the time of the display to the specified hour and minute.
      void timeTick()
      This method should get called once every minute - it makes the clock display go one minute forward.
      • Methods inherited from class java.lang.Object

        clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClockDisplay

        public ClockDisplay()
        Constructor for ClockDisplay objects. This constructor creates a new clock set at 00:00.
      • ClockDisplay

        public ClockDisplay​(int hour,
                            int minute)
        Constructor for ClockDisplay objects. This constructor creates a new clock set at the time specified by the parameters.
        Parameters:
        hour - The hour to use in setting time
        minute - The minute value to use in setting time
    • Method Detail

      • timeTick

        public void timeTick()
        This method should get called once every minute - it makes the clock display go one minute forward.
      • setTime

        public void setTime​(int hour,
                            int minute)
        Set the time of the display to the specified hour and minute.
        Parameters:
        hour - The hour to use in setting time
        minute - The minute value to use in setting time
      • getTime

        public java.lang.String getTime()
        Return the current time of this display in the format HH:MM.
        Returns:
        Returns the time as a string.