Java Reference
In-Depth Information
First, add ActionListener as an interface implemented by the SketcherFrame class:
public class SketcherFrame extends JFrame implements ActionListener {
The changes to the SketcherFrame class constructor to add the Help menu are:
public SketcherFrame(String title , Sketcher theApp) {
setTitle(title); // Set the
window title
this.theApp = theApp; // Save
app. object reference
setJMenuBar(menuBar); // Add the
menu bar to the window
setDefaultCloseOperation(EXIT_ON_CLOSE); // Default
is exit the application
createFileMenu(); // Create
the File menu
createElementMenu(); // Create
the element menu
createColorMenu(); // Create
the element menu
createToolbar();
toolBar.setRollover(true);
JMenu helpMenu = new JMenu("Help");
// Create Help
menu
helpMenu.setMnemonic('H');
// Create
Help shortcut
// Add the About item to the Help menu
aboutItem = new JMenuItem("About");
// Create
About menu item
aboutItem.addActionListener(this);
// Listener is
the frame
helpMenu.add(aboutItem);
// Add item to
menu
menuBar.add(helpMenu);
// Add Help
menu to menu bar
getContentPane().add(toolBar, BorderLayout.NORTH); // Add the
toolbar
getContentPane().add(statusBar, BorderLayout.SOUTH); // Add the
statusbar
}
Directory "Sketcher 2 displaying an About dialog"
Add aboutMenu as a private member of the SketcherFrame class:
Search WWH ::




Custom Search