-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHelpMenu.java
More file actions
executable file
·60 lines (49 loc) · 1.59 KB
/
HelpMenu.java
File metadata and controls
executable file
·60 lines (49 loc) · 1.59 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
import java.net.*;
import javax.help.*;
import javax.swing.*;
import java.awt.event.*;
public class HelpMenu {
JFrame f;
JMenuItem topics;
public HelpMenu() {
f = new JFrame("Menu Example");
JMenuBar mbar = new JMenuBar();
// a file menu
JMenu file = new JMenu("File");
JMenu help = new JMenu("Help");
// add an item to the help menu
help.add(topics = new JMenuItem("Help Topics"));
// add the menu items to the menu bar
mbar.add(file);
mbar.add(help);
// 1. create HelpSet and HelpBroker objects
HelpSet hs = getHelpSet("javahelp/road.hs");
HelpBroker hb = hs.createHelpBroker();
// 2. assign help to components
//CSH.setHelpIDString(topics, "top");
// 3. handle events
topics.addActionListener(new CSH.DisplayHelpFromSource(hb));
// attach menubar to frame, set its size, and make it visible
f.setJMenuBar(mbar);
f.setSize(500, 300);
f.setVisible(true);
}
/**
* find the helpset file and create a HelpSet object
*/
public HelpSet getHelpSet(String helpsetfile) {
HelpSet hs = null;
ClassLoader cl = this.getClass().getClassLoader();
try {
URL hsURL = HelpSet.findHelpSet(cl, helpsetfile);
hs = new HelpSet(null, hsURL);
} catch(Exception ee) {
System.out.println("HelpSet: "+ee.getMessage());
System.out.println("HelpSet: "+ helpsetfile + " not found");
}
return hs;
}
public static void main(String argv[]) {
new HelpMenu();
}
}