Thread Idioms

There are many ways you can write a program which uses threads. Certain ways of using threads are common. In this lesson we will go over three common methods of using threads:
1. Composing an applet of a class which implements Runnable.
2. Composing an applet of a class which extends Thread.
3. Creating an applet class which implements Runnable.
Composing an Applet of a Class Which Implements Runnable:

Click here for example


Composing an applet of a class which extends Thread:

Click here for example


Creating an Applet which implements Runnable:

Click here for example


Assignment: Convert the ccc2 applet from this lesson so that it is a single class which extends Applet and implements Runnable. You will do away with vert and horiz classes and use a single thread to time to drawing of the different colored boxes. You will want to leave most of the move class along except that you will create a run() method and a few other things. If you can do this without any assistance, then you understand threads well enough to continue. Otherwise, you should do some serious review of the material presented in the last few lessons. Also consider consulting an outside source for an explanation from another author. Different readers learn differently from different authors. Anyways, there are lots of tutorials about threads on the web! Keep that in mind for any topic you might find difficult.