In this discussion, we consider Java multimedia resources. These resources fall into several categories:
Loading images includes methods for loading and displaying a single image or a series of images to provide animation. Double buffering is used to avoid flickering in image display, caused by the time required to draw the image piecemeal on the screen. To compensate for thi delay, the image is constructed in its entirety off-screen and then displayed in a separate thread. Loading sound clips is similar to loading images. Finally, resources for handling video sequences are not yet available but are expected soon. In this discussion, we will consider only double buffering. Y
- Loading images
- Double buffering
- Loading sound clips
- Loading video
Double BufferringThe discussion will include three components. First, we look at the underlying concept on which double bufferring is based. Next, we look at the basic Java program strcuture for builidng double bufferring applications. Finally, a simple example program is presented, built uing ideas from the two earlier discussion.
ConceptThe basic idea behind double buffering is discussed. One declares a variable which will be used either to load an external image into or to draw on. In either case, the operations are done "off screen." A separate thread is started in which the image is displayed on the screen after the data in the off-screen variable are complete.
Program structureAn outline of a basic program structure for double buffering images is given. It follows the strategy outlined in the previous section.
Example programAn example program illustrates double bufferring, built using the program structure described in the previous section. It draws 10 randomly placed lines of randomly selected colors on the image at a time; in a separate thread, it then displays the "updated" image.
ReferencesReferences useful for this discussion include the following: