CIT 591 Images in Applets
Fall 2006, David Matuszek

Some students have had security manager problems when using a browser to execute an applet that includes images. I don't know what the cause of this problem is. Here is a very simple HTML page and applet that works for me in Firefox 2, IE 6, and Netscape 7.2.

<html>
  <head>
    <title>Using an image in an applet</title>
  <head>
  <body>
    <applet code="ImageInApplet.class" height="120" width="140">
    </applet>
  </body>
</html>
import java.awt.Graphics;
import java.awt.Image;
import javax.swing.JApplet;
 
public class ImageInApplet extends JApplet {
  
    public void paint(Graphics g) {
        Image duke = getImage(getDocumentBase(), "duke.gif");
        g.drawImage(duke, 10, 10, this);
    }
}
duke.gif duke.gif This isn't duke.gif, it's a running applet that displays duke.gif.