TDDI48: Lab1 - Generic Counters and Displays
Patrick Doherty (98/01/10)
Introduction
Observe that the applets used in this lab are implemented using Java 1.1. Your browser
may not be able to execute these applets!
This is the first lab in the course lab series. The idea is to implement a generic counter class and a generic
display framework used to display instantiations of the generic counter class. This will first be done as an application
and then as an applet. The lab consists of three parts:
- Part I -- Start by implementing subclasses of the abstract class Count. Each subclass will teach you
something about various datatypes in Java: integers, fonts, colors, Unicode characters, etc. After this is done,
implement a graphical interface to view the various counters. Emphasis is placed on separating the functionality
of the counters from their graphical representation. The display will initially be implemented as an application
and will teach you a great deal about the AWT package and the programming environment you will be using. In the
final exercise, you will transform the application into applets and place them on the web. A sample
of counter applets may be viewed to give you an idea of what is expected.
- Part II -- In part I, we attempted to provide a very clean and modular separation between the functionality
of our counters and their graphical display by implementing CountViewer as an abstract class with two abstract
methods: initDisplay and updateDisplay. For each new counter display, CountViewer was subclassed
and initDisplay and updateDisplay was implemented. There is a better way to structure the program.
The pattern we will use is based on the Smalltalk model/view/controller (MVC) paradigm. In this case, our model
is the abstract Count class, we can have an arbitrary number of views which would be Container classes implementing
displays for a specific counter, and the controller would be a three button panel which controls all displays.
To implement this pattern, we will use the Observer interface and Observable class supplied in the
java.util package. In this iteration, we will only implement an applet version. A sample
of counter applets using the MVC paradigm may be viewed to give you an idea of what is expected.
- Part III -- It could be argued that multiple displays of counters, although fun to implement, are relatively
useless. In the final exercise, choose a more reasonable model such as a clock or information structure, where
multiple views make more sense. Implement a new applet for the model using the MVC paradigm and provide at least
two different views. For example, a clock can be viewed in digital or analog form, an information source can be
viewed as a pie or bar diagram.
A few words of warning. Although completion of the lab does not involve much written code, it does involve a
great deal of thought and a thorough reading of the course books. Many aspects of Java are needed to complete the
lab and this is the point. All that you learn in this lab will be very useful in the other labs in the series and
will also familiarize you with the Symantec programming environment.
Exercises