import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JComponent;

@SuppressWarnings("serial")
public class Lightbulb extends JComponent {
	private boolean isOn;
	
	public void paintComponent(Graphics gc) {
		if (isOn) {
			gc.setColor(Color.YELLOW);
			gc.fillRect(0, 0, 100, 100);
		} else {
			gc.setColor(Color.BLACK);
			gc.fillRect(0, 0, 100, 100);
		}
	}
	
	public Dimension getPreferredSize() {
		return new Dimension(100,100);
	}
	
	public void flip() {
		isOn = !isOn;
		// in Swing you have to explicitly ask to repaint a component.
		// You should call repaint whenever the display of the
		// component changes.
		this.repaint();
	}
}

