Java Reference
In-Depth Information
Example
The applet below attempts to load an image (from the associated Web page's folder)
into an
ImageIcon
and then use the
ImageIcon
's
paintIcon
method to display the
image on the applet window.
import java.awt.*;
import javax.swing.*;
import java.net.*;
public class ImageTest2a extends JApplet
{
private ImageIcon image;
public void init()
{
image =
new ImageIcon(getDocumentBase(), " earth.gif");
}
public void paint(Graphics g)
{
image.paintIcon(this,g,0,0);
}
}
Surprisingly, the above applet produces an empty display in the appletviewer and
in IE9! Chrome is also empty of any image, but shows a grey rectangle in the top
left corner, where the applet output would be, as shown in Fig.
12.12
.
Fig. 12.12
Output from applet
ImageTest2a
under Chrome when path to image fi le removed
Search WWH ::
Custom Search