A menu presents several options in a menu bar or as a pop-up menu and is located in the expected window's title bar at the top of the screen. As you know, it enables the user to select a menu item. The user 's selection fires an action event. The following snippet is an example of using a menu: JMenuBar myMenuBar = new JMenuBar(); JMenu menu = new JMenu("first menu"); myMenuBar.add(menu); // the submenu "listens" for user selection JMenuItem myMenuItem = new JMenuItem("first submenu"); //actionListener was instantiated previously myMenuItem.addActionListener(actionListener); menu.add(myMenuItem); //last, add the menu bar to the frame // assume frame is initialized prviously frame.setJMenuBar(myMenuBar); |