/* A Swing version of the Lightswitch GUI program  */


import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;


@SuppressWarnings("serial")
class LightbulbWindow5 extends JFrame {
	public LightbulbWindow5() {
		super("On/Off Switch");
		
		JPanel panel = new JPanel();	
		this.add(panel);	
		
		JButton button = new JButton("On/Off");
		panel.add(button);
		
		Lightbulb bulb = new Lightbulb();
		panel.add(bulb);
		
		// "wire up" the bulb to the button
		button.addActionListener(new BulbSwitch(bulb));
		
		// Add a blinking light too
		Lightbulb blinker = new Lightbulb();
		panel.add(blinker);
		// Create a timer that will call actionPerformed() on the 
		// given TimerAction object every second (1000ms)
		Timer timer = new Timer(1000, new BulbSwitch(blinker));
		timer.start(); 
		panel.add(blinker);
		
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setSize(300,300);
		this.setVisible(true);
	}
	
}


class OnOff5 {
	public static void main(String[] args) {
		new LightbulbWindow5();
	}
}


