O'Reilly logo

Java™ After Hours: 10 Projects You'll Never Do at Work by Steven Holzner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required