// create a menu and keystroke accelerator object
// by merging all the relevant files.
// AutoMenu class finds what it needs via system properties.
AutoMenu menu = new AutoMenu();
frame.add(menu);

// hook up a method to be triggered when user hits a key
// or a menu item. We specify only the function name. We don't
// care if it represents a keystroke or menu item, or both.
menu.addActionListener ( "Open", new ActionListener()
                            {
                            public void actionPerformed (java.awt.event .ActionEvent e)
                               {
                               doAnOpen();
                               }
                            } );
menu.addActionListener ( "Close", new ActionListener()
                            {
                            public void actionPerformed (java.awt.event .ActionEvent e)
                               {
                               doAClose();
                               }
                            } );

// Ideally you would use a code generator to crank out all those anonymous inner Listener classes.

// You could then hide or reveal individual menu items like this:
// Function names must be unique for this to work.
// If you wanted two different Abouts on your menu, you would have
// to give them slightly different function names.
// We specify the function we want to change via its English name,
// not position. It is not an error if "About" is not on the
// current menu configuration,
// or if About is attached only to a keystroke,
// or if it is not attached to anything.
menu.setVisible("About" , false);

// you could gray out a menu item, but leave it visible,
// or disable a keystroke with:
menu.setEnabled("About" , false);