Java Reference
In-Depth Information
// Timer creates an action event.
public void actionPerformed (ActionEvent e) {
Object source = e.getSource ();
if (source == fTimer)
fClockPanel.repaint ();
}
// Stop clock when web page unloaded
public void stop () {
// Stop the clock updates.
fTimer.stop ();
}
} // class ClockTimer2
8.8 Concurrency utilities in J2SE 5.0
Java Release 5.0 adds numerous enhancements to the threading control and
concurrency features of Java. Some of the enhancements are advanced fea-
tures beyond the scope of this topic, and others require an understanding of
the new generics feature of 5.0. So we defer discussion of these until after we
have explained generics in Chapter 10.
8.9 Web Course materials
The Web Course Chapter 8: Supplements section provides additional information
and examples dealing with threading. This includes additional discussion of the
new java.util.concurrent tools available with Java 5.0.
In the Chapter 8: Te ch section we expand the number of histogram classes
and subclasses as we add new capabilities. For example, we create an adaptive
histogram class that can expand its range limits as new data arrives. We use timers
to simulate the reading of data to plot in a histogram. We also discuss sorting
tools in Java and use them to sort the bins in a histogram according to the number
of entries in the bins. We use a thread to animate the sorting of a histogram.
This increase in histogram classes illustrates a common challenge in object-
oriented programming: when to modify existing classes, when to create sub-
classes, and when to create whole new classes. Subclasses would seem the log-
ical answer for an OOP environment but many small revisions for every new
option that comes along can quickly lead to an unmanageable plethora of sub-
classes. Eventually, your entire class design may need to be re-worked (also called
refactoring , with the implication that common parts are factored out into a com-
mon superclass). We discuss class design and refactoring further in the Te ch
section. The Physics section looks at issues involved in animating simulations.
 
Search WWH ::




Custom Search