Java Reference
In-Depth Information
Figure 11.3. An ImageIconProxy object can stand in for an ImageIcon object because
an ImageIconProxy object is an ImageIcon object.
The constructor for ImageIconProxy accepts the name of an image file to eventually load.
When an ImageIconProxy object's load() method is called, it sets the image to
LOADING and starts a separate thread to load the image. Using a separate thread keeps the
application from hanging while the images loads. The load() method accepts a JFrame
object that the run() method calls back once the desired image is loaded. The almost-
complete code for ImageIconProxy.java is:
pacakage com.oozinoz.imaging;
import java.awt.*;
import javax.swing.*;
public class ImageIconProxy extends ImageIcon
implements Runnable
{
static final ImageIcon ABSENT =
new ImageIcon("absent.jpg");
static final ImageIcon LOADING =
new ImageIcon("loading.jpg");
ImageIcon current = ABSENT;
protected String filename;
protected JFrame callbackFrame;
Search WWH ::




Custom Search