Tell thread to suspend. Applet is about to be destroyed. Tell thread to terminate. This is actually a cleaner way of programming threads than willy-nilly declaring all kinds of objects to be Runnable . Note, by the way, how I did the synchronization in this example.
Synchronization only works if all concerned threads are synchronized on the same object.
So instead, I use a synchronized statement to synchronize on the thread object, runner . When used in the Runner class, this refers to the object of type Runner . Yes, but it's a little clumsy. Inside the nested Runner class, the applet object that is associated with the thread object, this , is referred to as RandomColorGridApplet.this . Event-handling is an even more natural application of nested classes.