home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-09-29 | 970 b | 41 lines |
- import java.awt.*;
-
- public class Light extends java.applet.Applet {
-
- Image light;
- boolean red = false;
- boolean yellow = false;
- boolean green = false;
-
- public void init() {
- light = getImage(getCodeBase(), "traffic.gif");
- }
-
- public void paint(Graphics g) {
- g.drawImage(light, 10, 10, this);
- if (red) {
- g.setColor(Color.red);
- g.fillOval(35,13,80,80);
- }
- if (yellow) {
- g.setColor(Color.yellow);
- g.fillOval(35,110,82,82);
- }
- if (green) {
- g.setColor(Color.green);
- g.fillOval(33,211,87,87);
- }
- }
-
- public void turnOn(String color) {
- red = false;
- yellow = false;
- green = false;
- if (color.equals("red")) red = true;
- if (color.equals("yellow")) yellow = true;
- if (color.equals("green")) green = true;
- repaint();
- }
-
- }
-