Best of 2008: A developer's list

JW blogger Dustin Marx names his top 10 technology events of 2008. Highlights include updates to Java SE 6, runtime support in OpenLaszlo 4.2, and the clash of the titans that occurred early in the year, when Sun acquired MySQL on the same day that Oracle announced its acquisition of BEA. No two lists are alike and it's not too late: What were your top 10 for 2008?

Also see:

Featured Whitepapers
Newsletter sign-up
View all newsletters

Sign up for our technology specific newsletters.

Enterprise Java
Email Address:

When static images just don't make the cut

Learn how to spice up your applets and applications<BR>with animated images

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Two months ago I showed you how to create an instance of the Image class given the URL of a file containing image data. Then, in last month's column, I showed you how to create an instance of the Image class given an instance of a class that implemented the ImageProducer interface. In both examples the rest of the application didn't know (or care, for that matter) how the Image object was created.

Let's examine the second case in a bit more detail.

True to its name, an image producer produces image data. The image producer in last month's column produced an image showing a color gradient. However, an image producer is not limited to generating (and regenerating) a single, static frame of image data; in fact, it is free to redefine the image data at any time.

Perhaps you can guess where I am going with this. After an image producer has produced one frame of image data, it is free to draw right on top of that frame to produce yet another frame of image data. Repeat this process a couple of times and, bam, you've got animation!

Whoah! Animation that easy? You bet. Let's take a closer look at how we can actually do this repetitive drawing.

The mechanics

Take a look at the illustration below, which shows the relationship between an image producer and one or more image consumers. As you know from our previous discussions, the image producer communicates information about the image data it is producing to one or more image consumers by invoking public methods on the image consumer. Image consumers then use this image information in a variety of ways -- to draw the image on the screen, for example. If you're feeling little lost about the whole concept of image producers and image consumers, take a quick detour back to last month's column before we move on.

The image producer/image consumer relationship


The interface between an image producer and an image consumer dictates the type of images that can be produced. With that in mind, let's look at two of the methods the ImageConsumer interface defines and the parameters those methods expect. The methods are the setHints() and imageComplete() methods. Let's begin at the end with the imageComplete() method, shown next:

imageComplete(int nStatus)

When an image producer calls an image consumer's imageComplete() method, it does so with the intent of informing the consumer about the status of the image reconstruction. The imageComplete() method requires an integer argument, which can be one of four values: IMAGEABORTED, IMAGEERROR, STATICIMAGEDONE, and SINGLEFRAMEDONE.

An image producer uses the arguments IMAGEABORTED and IMAGEERROR to indicate that something has gone wrong during the process of image production. It uses the argument STATICIMAGEDONE to indicate that image production is completely finished. Last of all, but central to our plan, it uses the argument SINGLEFRAMEDONE to indicate it has produced a single frame of image data but more frames may follow.

The following snippet demonstrates how an image producer would indicate to an image consumer that image production is complete:

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comment
Login
Forgot your account info?
Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources
  • Previous How-To Java articles