After building the basic window, we will next build the menus that are situated across the top of the window. This is done by, first, creating a
MenuBar
; second, creating the individualMenus
; third, creating the individualMenuItems
for each menu; fourth, adding the menus to the menubar; and, finally, adding the menubar to the window.Menus
MenuBar menuBar = new MenuBar ( ); Menu fileMenu = new Menu ("File"); Menu editMenu = new Menu ("Edit"); Menu helpMenu = new Menu ("Help"); public void init ( ){ // *** Build Menus fileMenu.add ( new MenuItem ( "New" ) ); fileMenu.add ( new MenuItem ( "Open" ) ); fileMenu.add ( new MenuItem ( "Close" ) ); fileMenu.add ( new MenuItem ( "Save" ) ); fileMenu.add ( new MenuItem ( "Quit" ) ); editMenu.add ( new MenuItem ( "Cut" ) ); editMenu.add ( new MenuItem ( "Copy" ) ); editMenu.add ( new MenuItem ( "Paste" ) ); editMenu.add ( new MenuItem ( "Delete" ) ); helpMenu.add ( new MenuItem ( "Help" ) ); menuBar .add ( fileMenu ); menuBar .add ( editMenu ); menuBar .add ( helpMenu ); menuBar .setHelpMenu ( helpMenu ); outerBox.setMenuBar ( menuBar ); // *** Build display outerBox. setLayout (new BorderLayout ( ) ); outerBox.add ("Center", centerPanel); outerBox.add ("South", bottomPanel); outerBox.resize (600, 500); outerBox. setBackground (Color.white); outerBox.show( ); } // end initRun the applet