Help: Using the Runnable Interface


Help is available for each task, or you can go straight to the solution source code.

Task 1

Modify the ClockPanel class to be Runnable, and add an appropriate run method.
Add "implements Runnable" to the class declaration. Copy the run method from the Clock class and change it to call repaint after the sleep pause, also remove the println call. Repaint will signal AWT to repaint the clock as soon as possible. It has no arguments.

Task 2

Have the ClockPanel create its own thread.
Add a variable of type Thread to ClockPanel. In the constructor of ClockPanel, initialize this variable with a new thread, then call the start method of the thread.

Task 3

Modify the run method to reference the new thread.
Change the call to the sleep method to reference the Thread variable created in the previous step.

Copyright © 1996-1997 MageLang Institute. All Rights Reserved.