Java Reference
In-Depth Information
// All the stuff for the previous menus and the toolbar, as before...
// Add the About item to the Help menu
aboutItem = new JMenuItem("About"); // Create the item
aboutItem.addActionListener(this); // Listener is the frame
helpMenu.add(aboutItem); // Add item to menu
menuBar.add(helpMenu); // Add the Help menu
}
Add aboutMenu as a private member of the SketchFrame class:
// Sundry menu items
private JMenuItem aboutItem;
Lastly, we need to implement the method in the SketchFrame class to handle the About menu
item's events:
// Handle About menu action events
public void actionPerformed(ActionEvent e) {
if(e.getSource() == aboutItem)
{
// Create about dialog with the app window as parent
AboutDialog aboutDlg = new AboutDialog(this, "About Sketcher",
"Sketcher Copyright Ivor Horton 2001");
}
}
You can now recompile SketchFrame.java to try out our smart new dialog.
Search WWH ::




Custom Search