Java Reference
In-Depth Information
private JMenuItem aboutItem;
// About menu
item
Lastly, you need to implement the method in the SketcherFrame class to handle the About menu item's
events:
// Handle About menu 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 2011");
}
}
Directory "Sketcher 2 displaying an About dialog"
You can now recompile SketcherFrame.java to try out your smart new dialog, which you can see in
Figure 20-3 .
FIGURE 20-3
The dialog pops up when you select the About item in the Help menu. Until you select the OK button in
the About Sketcher dialog, you can't interact with the application window because you created this as a
modal dialog. By changing the last argument in the call to the superclass constructor in the AboutDia-
log constructor, you can make it modeless and see how that works. This kind of dialog is usually modal,
though.
If you resize the application window before you display the About dialog, you will see that the position
of the dialog relative to the application window is adjusted accordingly.
 
 
Search WWH ::




Custom Search