Draw4 (other files are same as before)

MyCanvas.java  [download]

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class MyCanvas extends JPanel {
    // Remember in ivar so can redraw
    ImageIcon icon1, icon2; //*2 Remember images in ivar so can redraw

    MyCanvas () {
	icon1 = new ImageIcon ("redBall.gif"); //*1 Get the images
	icon2 = new ImageIcon ("blueBall.gif"); //*1
    }

    // This is our draw callback
    public void paintComponent (Graphics g) {
	super.paintComponent(g);
	
	icon1.paintIcon (this, g, 100, 100); //*3 Draw the images
	icon2.paintIcon (this, g, 200, 200); //*3

	g.drawLine (50, 50, 100, 50); //*4 Draw the line from previous examples
    }
}