-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11b_menu_actions.java
More file actions
67 lines (55 loc) · 2 KB
/
11b_menu_actions.java
File metadata and controls
67 lines (55 loc) · 2 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import javax.swing.*;
import java.awt.event.*;
public class GUIApp {
public static void main(String[] args) {
JFrame frame = new JFrame("Cupertinii Swing GUI");
frame.setSize(500, 500);
// Menu Bar contains Menu contains MenuItemx
JMenuBar myMenuBar = new JMenuBar();
JMenu menu = new JMenu("File");
JMenuItem item_new, item_save, item_saveas, item_exit;
item_new = new JMenuItem("New");
item_save = new JMenuItem("Save");
item_saveas = new JMenuItem("Save As");
item_exit = new JMenuItem("Exit");
JMenu options_submenu = new JMenu("Options");
JMenuItem item_change_color, item_change_size;
item_change_color = new JMenuItem("Change Color");
item_change_size = new JMenuItem("Change Size");
menu.add(item_new);
menu.add(item_save);
menu.add(item_saveas);
options_submenu.add(item_change_color);
options_submenu.add(item_change_size);
menu.add(options_submenu);
menu.add(item_exit);
myMenuBar.add(menu);
item_new.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
System.out.println("Clicked : " + source.getText() );
}
});
item_save.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
System.out.println("Clicked : " + source.getText() );
}
});
item_saveas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
System.out.println("Clicked : " + source.getText() );
}
});
item_exit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JMenuItem source = (JMenuItem) e.getSource();
System.out.println("Clicked : " + source.getText() );
}
});
frame.setJMenuBar(myMenuBar);
frame.setLayout(null);
frame.setVisible(true);
}
}