-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuBarClass.java
More file actions
executable file
·122 lines (87 loc) · 2.49 KB
/
MenuBarClass.java
File metadata and controls
executable file
·122 lines (87 loc) · 2.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/**This class is used to create a menu bar for each JFrame object.*/
import javax.swing.*;
import java.awt.event.*;
public class MenuBarClass {
//private field to hold menu bar object
private JMenuBar mBar;
//fields to hold menu objects
private JMenu file;
private JMenu getVote;
/**Constructor that will build the menu bar*/
public MenuBarClass()
{
//create a menu bar object
mBar = new JMenuBar();
//create menu objects and store them in the file and getVote fields
file=new JMenu("File");
getVote=new JMenu("Get Vote");
//create menu item objects and store them in the JMenuItem fields
JMenuItem item;
item=new JMenuItem("Reset");
item.addActionListener(new MenuBarActions());
file.add(item);
item=new JMenuItem("Vote");
item.addActionListener(new MenuBarActions());
file.add(item);
item=new JMenuItem("Save");
item.addActionListener(new MenuBarActions());
file.add(item);
item=new JMenuItem("Close");
item.addActionListener(new MenuBarActions());
file.add(item);
item=new JMenuItem("Overall");
item.addActionListener(new MenuBarActions());
getVote.add(item);
item=new JMenuItem("Gender");
item.addActionListener(new MenuBarActions());
getVote.add(item);
item=new JMenuItem("Age");
item.addActionListener(new MenuBarActions());
getVote.add(item);
item=new JMenuItem("Ethnicity");
item.addActionListener(new MenuBarActions());
getVote.add(item);
//add the two menus to the menu bar
mBar.add(file);
mBar.add(getVote);
}
/**Method that can be used to get the menu bar when creating a new JFrame
* object
* @return returns a JMenuBar object*/
public JMenuBar getMenuBar()
{
//return statement that will pass the menu bar
return mBar;
}
private class MenuBarActions implements ActionListener {
//public method to handle all events thrown by buttons in gui
public void actionPerformed(ActionEvent e)
{
//if statements to determine which button was clicked
if(e.getActionCommand().equals("Reset"))
{
}
else if (e.getActionCommand().equals("Vote"))
{
}
else if (e.getActionCommand().equals("Save"))
{
}
else if (e.getActionCommand().equals("Close"))
{
}
else if (e.getActionCommand().equals("Total"))
{
}
else if (e.getActionCommand().equals("Gender"))
{
}
else if (e.getActionCommand().equals("Age"))
{
}
else if (e.getActionCommand().equals("Ethnicity"))
{
}
}
}
}