Adding a Menu Bar to a Frame
public MenuFrame() {
JMenuBar menuBar = new JMenuBar() ;
setJMenuBar(menuBar) ; //Add menu bar to this frame
JMenu fileMenu = new JMenu(“File”) ;
menuBar.add(fileMenu) ; //Add File menu to menu bar
closeItem = new JMenuItem(“Exit”) ;
closeItem.addActionListener(this) ;
fileMenu.add(closeItem) ; //Add Exit item to menu
. . . Add other items and other menus
}
void actionPerformed(ActionEvent evt) {
. . . Respond to selection of menu item
}
private JMenuItem closeItem ;
. . .