Explaining TopAnnouncementActive Objects

Active Objects

We talked about creating animations, including a rather "pathetic" version of the pong game.

These examples involve creating classes extending ActiveObject.

To create an ActiveObject one must:

  1. define a class that "extends ActiveObject"

  2. define its constructor and say "start()" at the end.

  3. define a "public void run()" method.

  4. Include a pause statement inside any while loops in the run method. This is necessary both to slow the animation and to allow the processor to take care of other pending tasks.

Our first simple example is of a falling ball in a window with a Pong paddle. The Pong paddle can move at the same time that the ball falls. There is always one thread which handles the mouse motion methods (e.g., onMouseMove), so this program will have two threads operating concurrently: one which moves the paddle and the other which moves the ball.

Actually, we will consider a definition of a moving Pong ball that just falls rather than bouncing off the walls or paddle. This makes for a pretty boring pong game, but it does demonstrate the basics of ActiveObjects.

Active objects allow us to create animations by creating new threads along with the objects, so that the "event" thread can respond to mouse actions, while the "ActiveObject" continues to execute.


Explaining TopAnnouncementActive Objects