-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDialogFrame.java
41 lines (31 loc) · 1.12 KB
/
DialogFrame.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package dialog;
import javax.swing.*;
/**
* A frame with a menu whose File->About action shows a dialog.
*/
public class DialogFrame extends JFrame {
private static final int DEFAULT_WIDTH = 300;
private static final int DEFAULT_HEIGHT = 200;
private AboutDialog dialog;
public DialogFrame() {
setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
// Construct a File menu.
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
JMenu fileMenu = new JMenu("File");
menuBar.add(fileMenu);
// Add About and Exit menu items.
// The About item shows the About dialog.
JMenuItem aboutItem = new JMenuItem("About");
aboutItem.addActionListener(event -> {
if (dialog == null) // first time
dialog = new AboutDialog(DialogFrame.this);
dialog.setVisible(true); // pop up dialog
});
fileMenu.add(aboutItem);
// The Exit item exits the program.
JMenuItem exitItem = new JMenuItem("Exit");
exitItem.addActionListener(event -> System.exit(0));
fileMenu.add(exitItem);
}
}