home *** CD-ROM | disk | FTP | other *** search
/ Laura Lemay's Web Workshop: ActiveX & VBScript / Laura_Lemays_Web_Workshop_ActiveX_and_VBScript_Version_1.0_1997.iso / source / chapter15 / 15lax04.java < prev    next >
Text File  |  1996-09-29  |  970b  |  41 lines

  1. import java.awt.*;
  2.  
  3. public class Light extends java.applet.Applet {
  4.  
  5.     Image light;
  6.     boolean red = false;
  7.     boolean yellow = false;
  8.     boolean green = false;
  9.  
  10.     public void init() {
  11.         light = getImage(getCodeBase(), "traffic.gif");
  12.     }
  13.  
  14.     public void paint(Graphics g) {
  15.         g.drawImage(light, 10, 10, this);
  16.         if (red) {
  17.             g.setColor(Color.red);
  18.             g.fillOval(35,13,80,80);
  19.         }
  20.         if (yellow) {
  21.             g.setColor(Color.yellow);
  22.             g.fillOval(35,110,82,82);
  23.     }
  24.         if (green) {
  25.             g.setColor(Color.green);
  26.             g.fillOval(33,211,87,87);
  27.     }
  28.     }
  29.  
  30.     public void turnOn(String color) {
  31.         red = false;
  32.         yellow = false;
  33.         green = false;
  34.         if (color.equals("red")) red = true;
  35.         if (color.equals("yellow")) yellow = true;
  36.         if (color.equals("green")) green = true;  
  37.         repaint();      
  38.     } 
  39.  
  40. }
  41.