/* * Gary Cornell and Cay S. Horstmann, Core Java (Book/CD-ROM) * Published By SunSoft Press/Prentice-Hall * Copyright (C) 1996 Sun Microsystems Inc. * All Rights Reserved. ISBN 0-13-565755-5 * * Permission to use, copy, modify, and distribute this * software and its documentation for NON-COMMERCIAL purposes * and without fee is hereby granted provided that this * copyright notice appears in all copies. * * THE AUTHORS AND PUBLISHER MAKE NO REPRESENTATIONS OR * WARRANTIES ABOUT THE SUITABILITY OF THE SOFTWARE, EITHER * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. THE AUTHORS * AND PUBLISHER SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING * THIS SOFTWARE OR ITS DERIVATIVES. */ /** * @version 1.00 07 Feb 1996 * @author Cay Horstmann */ import java.awt.*; public class MenuTest extends Frame { public MenuTest() { setTitle("MenuTest"); MenuBar mbar = new MenuBar(); Menu m = new Menu("File"); m.add(new MenuItem("New")); m.add(new MenuItem("Open")); m.addSeparator(); m.add(new MenuItem("Save")); m.add(new MenuItem("Save As")); m.addSeparator(); m.add(new MenuItem("Print")); m.addSeparator(); m.add(new MenuItem("Quit")); mbar.add(m); m = new Menu("Edit"); m.add(new MenuItem("Undo")); m.add(new MenuItem("Redo")); m.addSeparator(); m.add(new MenuItem("Cut")); m.add(new MenuItem("Copy")); m.add(new MenuItem("Delete")); m.add(new MenuItem("Paste")); m.addSeparator(); Menu f = new Menu("Options"); f.add(new CheckboxMenuItem("Insert mode")); f.add(new CheckboxMenuItem("Auto indent")); m.add(f); mbar.add(m); m = new Menu("Help"); m.add(new MenuItem("Index")); m.add(new MenuItem("About")); mbar.add(m); setMenuBar(mbar); } public boolean action(Event evt, Object arg) { if (evt.target instanceof MenuItem) { if(arg.equals("Quit")) System.exit(0); } else return false; return true; } public boolean handleEvent(Event evt) { if (evt.id == Event.WINDOW_DESTROY && evt.target == this) System.exit(0); return super.handleEvent(evt); } public static void main(String args[]) { Frame f = new MenuTest(); f.resize(300, 200); f.show(); } }