
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
An MVC Clock
|
405
Example 18-6 shows the code for the ClockUpdate class.
The ClockAnalogView and ClockDigitalView Classes
The ClockAnalogView and ClockDigitalView classes extend AbstractView, which
implements the Observer and View interfaces. They are display-only views; that is,
the user interface they create has no inputs and therefore needs no controller.
Accordingly, neither ClockAnalogView nor ClockDigitalView overrides the
AbstractView.defaultController( ) method. Both classes simply use
null as their con-
troller, as returned by the AbstractView.defaultController( ) method. If you were to
make the clock hands on the analog display draggable, you would implement an
appropriate controller class to notify the model of the specified input obtained via
the view’s GUI. Likewise, if the hours, minutes, and seconds of the digital clock were
editable, you would implement an appropriate controller for that view as well.
The ClockAnalogView class is responsible for rendering the clock as a traditional cir-
cle with moving hands. The ClockDigitalView class is responsible for rendering the
clock as a numeric display. Both classes have the same basic structure, which
includes the following two public methods:
makeClock( )
Creates the visual display of the clock at construction time
update( )
Handles ...