The Tortoise and The Hare

race.java implements the historically proverbial race between the Tortoise and the Hare. The Tortoise is slow but sure, and the Hare is quick but suffering from attention deficit disorder, he can't focus on the race at hand. To spice things up the Tortoise nastily nips the Hare in the butt with his sharp, sharp teeth whenever he's in range of his arch-nemesis, the Bunny Rabbit. Be warned, this applet has adult content in terms of blood and gore.

So anyway, the position and height of both the Tortoise and Hare are updated by synchronized threads. My applet only uses sleep(), wait(), and notify() to manage its threads because resume(), suspend(), and stop() have all been deprecated in JDK 1.2. (This is because they are such dangerous methods! Read more about why they were deprecated.) The methods are locked so that only one thread can update position at a time. This closely simulates the ticking of a clock in that no move is made by one animal until the other animal has taken their turn. These threads, along with a thread that repaints the applet window every so often, run until an animal has reached the finish line.

This applet is also double buffered to reduced flickering. While the paint method is drawing images to the buffer image it checks to see how close the competitors are and, if appropriate, draws the quarreling versions of the Tortoise and Hare.

by Ken Beinert