-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTopMenuBar.java
62 lines (54 loc) · 2 KB
/
TopMenuBar.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package org.gradient.waves;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* <h1>Top Menu Bar</h1>
* Top menu bar is serving the purpose to help the new user
* understand the logic, constraints and nuances of the program.
* <br>
* It contain one Help JMenu, which contains the JMenu items,
* which navigate to tips for the load and save buttons.
* @see JMenu
* @see JMenuItem
*/
public class TopMenuBar extends JMenuBar {
public TopMenuBar() {
JMenu jmHelp = new JMenu("Help");
JMenuItem jmiAboutLoad = new JMenuItem("About Load");
JMenuItem jmiAboutSave = new JMenuItem("About Save");
HelpListener helpListener = new HelpListener(this);
jmiAboutLoad.addActionListener(helpListener);
jmiAboutSave.addActionListener(helpListener);
jmHelp.add(jmiAboutLoad);
jmHelp.add(jmiAboutSave);
this.add(jmHelp);
}
/**
* HelpListener is the class to handle the button generated events,
* which implements the ActionListener class.
* @see ActionListener
*/
static class HelpListener implements ActionListener {
private TopMenuBar topMenuBar;
public HelpListener(TopMenuBar topMenuBar) {
this.topMenuBar = topMenuBar;
}
/**
* actionPerformed() here based on the JMenuItem dislpays different text
* in showMessageDialog.
* @see JOptionPane
*
* @param ev the event to be processed
*/
public void actionPerformed(ActionEvent ev) {
if (ev.getActionCommand().equals("About Load")) {
JOptionPane.showMessageDialog(topMenuBar,
"Couldn't think of helping text about the load yet :)");
} else {
JOptionPane.showMessageDialog(topMenuBar,
"Couldn't think of helping text about the save yet :)");
}
}
}
}