Basic HTML version of Foils prepared Sept 21 1998

Foil 55 Frames can have MenuBars

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

classes for menus in frames for Foil 55
1 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
2 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); } }
3 Note that there are also CheckboxMenuItems, submenus,and (new) MenuShortcuts.

in Table To:


© 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 Sat Nov 28 1998