Loading and Drawing an Image in an Applet - Java Applet

Java examples for Applet:Applet Creation

Description

Loading and Drawing an Image in an Applet

Demo Code

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.Image;

class BasicApplet extends Applet {
  Image image;/*from w  w  w  . ja  va2  s  .  c o m*/

  public void init() {
    // Load image
    image = getImage(getDocumentBase(), "http://hostname/image.gif");
  }

  public void paint(Graphics g) {
    // Draw image
    g.drawImage(image, 0, 0, this);
  }
}

Related Tutorials