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

public class ButtonApplet extends JApplet
{
    JButton button;
    JCheckBox checkbox;
    
    public void init() 
    {
		JPanel contentPane = (JPanel)getContentPane();
		contentPane.setLayout(new FlowLayout());
	
		button = new JButton("OK");
		checkbox = new JCheckBox("Beep when button is pressed", true);
		contentPane.add(checkbox);
		contentPane.add(button);
	
		// 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(checkbox.isSelected())
		{
	    		Toolkit.getDefaultToolkit().beep();
		}
    }
}
