import java.applet.*;
import java.awt.*;

public class radio extends Applet

{
  public void init()
	{
	  add(new Label("The 4 radio buttons will change the screen color."));
	  CheckboxGroup colors = new CheckboxGroup();
	  add(new Checkbox("Red",colors,false));
	  add(new Checkbox("White",colors,false));
	  add(new Checkbox("Green",colors,false));
	  add(new Checkbox("Blue",colors,false));
	  add(new Label("Notice that you can only select one radio button."));
	  add(new Label("Selecting a radio button triggers an event"));
	  add(new Label("that we use to change the screen color."));
	}

public boolean action(Event evt, Object whichAction)
	{
	  Checkbox currentCheckbox = (Checkbox)evt.target;
	  boolean checkboxState = currentCheckbox.getState();
	  if (currentCheckbox.getLabel() == "Red")
		if (checkboxState)
		{
		  setBackground(Color.red);
		}
	 if (currentCheckbox.getLabel() == "White")
		if (checkboxState)
		{
		  setBackground(Color.white);
		}
	 if (currentCheckbox.getLabel() == "Green")
		if (checkboxState)
		{
		  setBackground(Color.green);
		}
	 if (currentCheckbox.getLabel() == "Blue")
		if (checkboxState)
		{
		  setBackground(Color.blue);
		}	
	 repaint();
	 return true;
	}
}
