FileDocCategorySizeDatePackage
OrderForm.javaAPI DocExample1434Fri Feb 14 02:12:50 GMT 1997None

OrderForm.java

import java.awt.*;
import java.awt.event.*;

public class OrderForm extends java.applet.Applet implements ActionListener { 
	Panel condimentsPanel = new Panel();
	CheckboxGroup entreeGroup = new CheckboxGroup();

	public void init() {
		condimentsPanel.add( new Checkbox("Ketchup"));
		condimentsPanel.add( new Checkbox("Mustard"));
		condimentsPanel.add( new Checkbox("Pickles"));

		Checkbox c;
		Panel entreePanel = new Panel();
		entreePanel.add( c = new Checkbox("Beef") );
		c.setCheckboxGroup( entreeGroup );
		entreePanel.add( c = new Checkbox("Chicken") );
		c.setCheckboxGroup( entreeGroup );
		entreePanel.add( c = new Checkbox("Veggie") );
		c.setCheckboxGroup( entreeGroup );
		entreeGroup.setCurrent( c );

		Panel orderPanel = new Panel();
		Button orderButton = new Button("Place Order");
		orderButton.addActionListener( this );
		orderPanel.add( orderButton );

		setLayout( new GridLayout(3, 1) );
		add( entreePanel );
		add( condimentsPanel );
		add( orderPanel );
	}
	public void actionPerformed(ActionEvent e) {
		takeOrder();
	}
	
	void takeOrder() {
		Checkbox c = entreeGroup.getCurrent();
			System.out.println( c.getLabel() + " sandwich" );

		Component [] components = condimentsPanel.getComponents();
		for (int i=0; i< components.length; i++)
			if ( (c = (Checkbox)components[i]).getState() )
				System.out.println( "With " + c.getLabel() );
		System.out.println("Thank you, drive through...");
	}
}