Basic HTML version of Foils prepared 13 October 97

Foil 55 Frames can have MenuBars

From Java Tutorial, July 1, 1996 CSC499(JSU) CPS406/606 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox

classes for menus in frames for Foil 55
A Frame has a set of classes to define MenuBars and Menus:
  • Menubar mbar = new MenuBar(); // defines a menubar which can be used in a frame
Several Menus, which each have menu items, can be added to the menubar:
Menu typeMenu = new Menu("Type");
typeMenu.add(new MenuItem("Black/White"));
typeMenu.add(new MenuItem("Color"));
typeMenu.addSeparator();
MenuItem q = new MenuItem("Quit"); q.addActionListener;
  • typeMenu.add ( q );
  • mbar.add(typeMenu);
  • When the user selects an item on a menu, an ActionEvent is reported to the ActionListener, where it can be handled
  • public void actionPerformed(ActionEvent e)
  • { if (e.getSource() == q)
    • { q.setVisible(false); } }
Note that there are also CheckboxMenuItems, submenus, and (new) MenuShortcuts.



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Wed Apr 1 1998