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

public class RadioButtonApplet extends JApplet
{
    JButton button;
    ButtonGroup group;
    JRadioButton greenButton, blueButton, redButton;
    
    public void init() 
    {
		JPanel contentPane = (JPanel)getContentPane();
		contentPane.setLayout(new FlowLayout());
	
		button = new JButton("OK");
		greenButton = new JRadioButton("Green");
		blueButton = new JRadioButton("Blue");
		redButton = new JRadioButton("Red");
	
		contentPane.add(greenButton);
		contentPane.add(blueButton);
		contentPane.add(redButton);
		contentPane.add(button);
	
		// Create a ButtonGroup and add the radio buttons--
		// this allows the buttons to be mutually exclusive
		group = new ButtonGroup();
		group.add(greenButton);
		group.add(blueButton);
		group.add(redButton);
	
		// don't worry too much about this for now--
		// it sets up a handler for button press events.
		button.addActionListener(new ActionListener()
		{
	    		public void actionPerformed(ActionEvent evt)
	    		{
				doMyButtonAction();
	    		}
		});	
    }
    
    // Perform an action when the button is pressed,
    // but only if the checkbox is selected
    public void doMyButtonAction()
    {
		if(greenButton.isSelected())
		{
	   		 button.setForeground(Color.green);
		}
		else if(blueButton.isSelected())
		{
	   		 button.setForeground(Color.blue);
		}
		else if(redButton.isSelected())
		{
	   		button.setForeground(Color.red);
		}
    }
}
