Example of Drawing Images

lightbulb 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 | Cafe au Lait

Copyright 1997, 1999, 2000, 2002 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified December 28, 2002