![]() |
Using the Runnable Interface
This Magercise shows how to use the Runnable interface to add liveness to an object. Here a Clock class is given. It is implemented by subclassing Thread. The goal is to create a clock that is an AWT component and achieves liveness by implementing the Runnable interface and creating its own thread. The ClockPanel class is given as a starting point for the new clock, it includes almost all the AWT code needed for the new clock. By using the Runnable interface instead of inheriting from the Thread class, the ClockPanel is free to inherit from the AWT class Panel, and can hide control of its thread from other objects. Work LocationPerform all work for this magercise in VisualAge project MageLang Magercises, package magercises.Using the Runnable Interface. If this project does not appear in your Workspace add it from the repository (if it exists there) or create a new project using this name. Tasks
Perform the following tasks:
Have the ClockPanel create its own thread. Modify the run method to reference the new thread.
|
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |