The drawImage()
methods returns a
boolean
. Many people don't realize this, since the return
value of drawImage()
is often ignored. However, that
boolean
tells you whether or not the image was drawn
successfully. If it was, drawImage()
returns
true
. Otherwise drawImage()
returns
false
.
For example, the following applet loads an image from the net. Until the image is finished loading, the applet displays the words "Loading Picture. Please hang on." Once the image has fully loaded, the applet displays it.
import java.awt.*;
import java.applet.*;
import java.awt.image.*;
public class ImageDisplay extends Applet {
private Image picture;
public void init() {
this.picture = this.getImage(this.getDocumentBase(), "sun.gif");
}
public void paint(Graphics g) {
if(!g.drawImage(this.picture, 0, 0, this)) {
g.drawString("Loading Picture. Please hang on", 25, 50);
}
}
}