//ImageIconDemo.java import java.awt.*; import javax.swing.*; //ImageIcon not just for icons. for any image file. public class ImageIconDemo extends JApplet { ImageIcon myimageicon; int iconWidth, iconHeight; public void init() { //works in appletviewer: //myimageicon = new ImageIcon("trees.gif"); //works in appletviewer and web browser: myimageicon = new ImageIcon(getClass().getResource("trees.gif")); //size of image: optional, for use by drawImage iconWidth = myimageicon.getIconWidth(); iconHeight = myimageicon.getIconHeight(); //the above could be done in paint } public void paint(Graphics g) { //one way to display the ImageIcon: myimageicon.paintIcon( this, g, getWidth()/2, getHeight()/2); //(this,g, x,y) //another way to display the ImageIcon: //scaled image icon: here is half size: g.drawImage( myimageicon.getImage(), 0, 20, iconWidth/2, iconHeight/2, this); // ( , x, y, width, height, this) } } /* effect of non-existent file: crash. magnify to see pixelation. use a JPEG. view in Picture Viewer. animated gif border of icon1.png. lilies in frame */