Moving Those Fish

Applications that draw using sprites often do their drawing in a new execution stream—that is, a new thread. The reason for this is because while the new thread draws the sprites and moves them around, the main thread in the application can be doing other things—such as, in this application, closing the window when the user clicks the close button.

The drawing and graphics work that goes on behind the scenes will take place in this new thread. To handle a new thread, you make sure that an application implements the Runnable interface:

import java.awt.*;
import java.awt.event.*;

public class Aquarium extends Frame implements Runnable
{
        .
        .
        .
}

The Runnable interface has only one method, run, which is called when you start a ...

Get Java™ After Hours: 10 Projects You'll Never Do at Work now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.