Example of Drawing Images

This image was loaded with this <APPLET> tag:

<applet code="DisplayImage" width=158 height=189>
<PARAM name=imagefile value=lightbulb.gif>
<img src=lightbulb.gif width=158 height=189>
</applet>
Here's the code that produced it:

import java.awt.*;
import java.applet.*;


public class DisplayImage extends Applet {

  private Image picture;

  public void init() {
  
    String filename = this.getParameter("imagefile");
    if (filename != null) {
      this.picture = this.getImage(this.getDocumentBase(), filename);
    }
  
  }
  
  public void paint(Graphics g) {
   
    if (this.picture != null) {
      g.drawImage(this.picture, 0, 0, this);
    }
    else {
      g.drawString("Missing Picture", 20, 20);
    }
    
  }

}

Previous | Next | Top
Last Modified April 10, 2000
Copyright 1997, 1999, 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu