Java Reference
In-Depth Information
Code 3.4
Implementation of the
ClockDisplay
class
/**
* 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.
*
* @author Michael K├Âlling and David J. Barnes
* @version 2011.07.31
*/
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; // simulates the actual display
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at 00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
updateDisplay();
}
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the
* parameters.
*/
public ClockDisplay( int hour, int minute)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
setTime(hour, minute);
}
/**
* This method should get called once every minute - it
* makes the clock display go one minute forward.
*/
Search WWH ::




Custom Search