/* Name: Chris Johnson johnson@dcs.gla.ac.uk Last modified: 27/10/98 Description: Draws a light onto an already existing canvas - A_Light takes in a String and X,Y coordinates. The string sets the color of the light. Initially, the light is not lit. From an idea originally suggested by: Quintin Blane (qablane@surfaid.org) */ import java.awt.*; import java.applet.Applet; public class A_Light { private Color Bulb_color = Color.red; private boolean On = false; // true if the light is lit private int X = 0; private int Y = 0; static int height = 50; static int width = 50; A_Light(String the_color, int X_pos, int Y_pos) // constructor { if(the_color.equals("Amber")) Bulb_color = Color.orange; else if (the_color.equals("Green")) Bulb_color = Color.green; else Bulb_color = Color.red; X = X_pos; Y = Y_pos; } public void on(){ // turn the light on this.On = true; } public void off(){ // turn the light off this.On = false; } public boolean is_on(){ // is the light on? return this.On; } public Color The_Color() // what color is the light? { return this.Bulb_color; } public void paint(Graphics g){ // draw the light onto g - the light is drawn as a filled // oval if it is on - if it is off then only the outline of // the oval is drawn. The color of the light is given by // its bulb value (see constructor) g.setColor(this.Bulb_color); if (On) g.fillOval(X, Y, width, height); else g.drawOval(X, Y, width, height); } }