Java Graphics  «Prev  Next»
Lesson 7Drawing images
ObjectiveDraw images.

Drawing Java Images using the legacy AWT

Drawing images in Java is very straightforward. To draw an image, you use one of the drawImage() methods defined in the Graphics class. Following is the simplest of the drawImage() methods:

The first three parameters to drawImage() specify the Image object to be drawn, along with its XY position. The image is drawn with its upper left corner at this position.
Draw Images

The Applet class implements the ImageObserver interface, so you can pass it along as the last parameter, as the following example demonstrates:

public void paint(Graphics g) {
  g.drawImage(img, 20, 20, this);

Draw Images Exercise

Click the Exercise link to load and draw images.
Draw Images Exercise

Slideshow Applet - Exercise

Once you mastered loading and drawing images, one will be ready to start building your interactive slide show applet.
Slideshow Applet - Exercise