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); } }
|