FileDocCategorySizeDatePackage
MenuClass.javaAPI DocExample2536Mon Mar 08 11:54:38 GMT 2004org.cookbook.ch09

MenuClass

public class MenuClass extends Object

Fields Summary
Display
display
Shell
shell
Menu
menuBar
Menu
fileMenu
Menu
editMenu
MenuItem
fileMenuHeader
MenuItem
editMenuHeader
MenuItem
fileExitItem
MenuItem
fileSaveItem
MenuItem
fileEnglishItem
MenuItem
fileGermanItem
MenuItem
editCopyItem
Text
text
Constructors Summary
public MenuClass()

		display = new Display();
		shell = new Shell(display);
		shell.setText("Menu Example");
		shell.setSize(300, 200);

		text = new Text(shell, SWT.BORDER);
		text.setBounds(80, 50, 150, 25);

		menuBar = new Menu(shell, SWT.BAR);
		fileMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
		fileMenuHeader.setText("&File");

		fileMenu = new Menu(shell, SWT.DROP_DOWN);
		fileMenuHeader.setMenu(fileMenu);

		fileSaveItem = new MenuItem(fileMenu, SWT.PUSH);
		fileSaveItem.setText("&Save");

		fileEnglishItem = new MenuItem(fileMenu, SWT.RADIO);
		fileEnglishItem.setText("English");

		fileGermanItem = new MenuItem(fileMenu, SWT.RADIO);
		fileGermanItem.setText("German");

		fileExitItem = new MenuItem(fileMenu, SWT.PUSH);
		fileExitItem.setText("E&xit");

		editMenuHeader = new MenuItem(menuBar, SWT.CASCADE);
		editMenuHeader.setText("&Edit");

		editMenu = new Menu(shell, SWT.DROP_DOWN);
		editMenuHeader.setMenu(editMenu);

		editCopyItem = new MenuItem(editMenu, SWT.PUSH);
		editCopyItem.setText("&Copy");

		fileExitItem.addSelectionListener(new MenuItemListener());
		fileSaveItem.addSelectionListener(new MenuItemListener());
		editCopyItem.addSelectionListener(new MenuItemListener());

		fileEnglishItem.addSelectionListener(new RadioItemListener());
		fileGermanItem.addSelectionListener(new RadioItemListener());

		shell.setMenuBar(menuBar);
		shell.open();
		while (!shell.isDisposed())
		{
			if (!display.readAndDispatch())
				display.sleep();
		}
		display.dispose();
	
Methods Summary
public static voidmain(java.lang.String[] args)

		MenuClass menuExample = new MenuClass();