import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class H12_Oefening3 extends JFrame
{
	private JCheckBox vak1, vak2;
	private JPanel vakPanel;
	private boolean standSchakelaar1, standSchakelaar2;
	
	public H12_Oefening3()
	{
		super("Schakelaar");
		
		Container container = getContentPane();
		container.setLayout(new BorderLayout());
		
		vakPanel = new JPanel(new GridLayout(1,2));
		
		standSchakelaar1 = false;
		standSchakelaar2 = true;
		vak1 = new JCheckBox("Schakelaar1", standSchakelaar1);
		vakPanel.add(vak1);
		vak2 = new JCheckBox("Schakelaar2", standSchakelaar1);
		vakPanel.add(vak2);
		
		CheckBoxHandler handler = new CheckBoxHandler();
		
		vak1.addItemListener(handler);
		vak2.addItemListener(handler);
		
		container.add(vakPanel,BorderLayout.SOUTH);
		
		setSize(400,250);
		setVisible(true);
	}

	public static void main(String args[])
	{
		H12_Oefening3 application = new H12_Oefening3();
		application.setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
	
	private class CheckBoxHandler implements ItemListener
	{
		public void itemStateChanged(ItemEvent event)
		{
			if (event.getSource() == vak1);
				if (event.getStateChange() == ItemEvent.SELECTED)
					standSchakelaar1 = true;
				else
					standSchakelaar1 = false;
				
			if (event.getSource() == vak2);
				if (event.getStateChange() == ItemEvent.SELECTED)
					standSchakelaar2 = true;
				else
					standSchakelaar2 = false;
			
		}
	}
}