FileDocCategorySizeDatePackage
DinnerMenu.javaAPI DocExample1418Sat Feb 15 03:28:54 GMT 1997None

DinnerMenu.java

import java.awt.*;
import java.awt.event.*;
import java.util.EventListener;

public class DinnerMenu extends java.applet.Applet { 
	public void init() {
		new DinnerFrame().show();
 	}
}

class DinnerFrame extends Frame implements ActionListener, ItemListener {
	DinnerFrame() {
		setTitle("Dinner Helper");
		setLayout( new FlowLayout() );

		add( new Label("Food") );
		Choice c = new Choice ();
		c.addItem("Chinese");
		c.addItem("Italian");
		c.addItem("American");
		c.addItemListener( this );
		add( c );

		Menu menu = new Menu("Utensils");
		menu.add( makeMenuItem("Fork") );
		menu.add( makeMenuItem("Knife") );
		menu.add( makeMenuItem("Spoon") );
		Menu subMenu = new Menu("Hybrid");
		subMenu.add( makeMenuItem("Spork") );
		subMenu.add( makeMenuItem("Spife") );
		subMenu.add( makeMenuItem("Knork") );
		menu.add( subMenu);
		menu.add( makeMenuItem("Quit") );

		MenuBar menuBar = new MenuBar();
		menuBar.add(menu);
		setMenuBar(menuBar);
		pack();
	}
	public void itemStateChanged(ItemEvent e) {
		System.out.println( "Choice set to: " + e.getItem() );
	}
	public void actionPerformed(ActionEvent e) {
		String command = e.getActionCommand();
		if ( command.equals( "Quit" ) )
			dispose();
		else
			System.out.println( "Menu selected: " + e.getActionCommand() );
	}
	private MenuItem makeMenuItem( String name ) {
		MenuItem m = new MenuItem( name );
		m.addActionListener( this );
		return m;
	}
}