
All of the drawImage() methods of the Graphics objects requir eanjava.awt.-
image.ImageObserver object. This is the object that handles things if you try to
draw an image that is not fully loaded. Fortunately,
java.awt.Component imple-
ments
ImageObserver,soyou can use any Component or Applet object for this
method argument.
If are writing an applet and want to load a predefined image from a URL, you can
use the
getImage() method defined by the java.applet.Applet class. This
method begins downloading the specified image and retur ns an
Image object to
you immediately.
If you are writing a standalone application and want to load a predefined image
fr om a file or URL, use one of the
getImage() or createImage() methods of the
java.awt.Toolkit class:
Toolkit.getDefaultToolkit().getImage("myimage.gif");
Like the getImage() method of Applet, these Toolkit methods start loading the
image and immediately retur nan
Image object. The image formats supported by
these
Applet and Toolkit methods are implementation dependent. Most imple-
mentations support common formats, such as GIF (including transparent GIF),
JPEG, and XBM.
To ensur e that an
Image object is fully loaded before you use it, you can create a
java.awt.MediaTracker object, pass your Image to its addImage() method, then
call the
waitForAll() method.
To create an empty off-scr een image that you can draw into and copy pixels out
of, call the
createImage() method ...