11.6 Creating a Menu |
MenuBar menuBar = new MenuBar(); Menu fileMenu = new Menu("File"); MenuItem quitItem = new MenuItem("Quit"); menuBar.add(fileMenu); fileMenu.add(quitItem); quitItem.addActionListener( new QuitActionListener() );To add the menu bar to a Frame you would call the setMenuBar() method on the frame. For example
setMenuBar(menuBar);Notice how the quitItem object is associated with an ActionListener. The code on the ActionListener will be triggered when the Quit option is selected from the file menu.