/* * File: Lights.java * Author: Java, Java, Java * Description: This applet loads a pair of image * files and displays them. The java.applet.Applet.getImage() * method is used to load the files. Two Image variables * are used to refer to the images in the program's memory. */ import java.applet.*; import java.awt.*; public class Lights extends Applet { private Image lightOn, lightOff; // Declare two Image variables /** * The init() method loads the images from GIF files. */ public void init() { lightOn = getImage(getCodeBase(),"lighton.gif"); lightOff = getImage(getCodeBase(),"lightoff.gif"); } // init() /** * The paint() method is called automatically after init(). * It uses the applet's Graphics object to display the images. * @param Graphics g provides a reference to the applet's Graphics object */ public void paint (Graphics g) { g.drawImage(lightOn, 10, 10, this); g.drawImage(lightOff, 70, 10, this); } // paint() } // Lights