import java.net.*; import javax.help.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class DrawIt extends JFrame { private JMenuBar menuBar; private JButton colorHelp, colorButton, RGBButton, newButton, CSHHelp; private JPanel drawArea; public DrawIt() { super("Draw-It"); createGUI(); //A very Simple GUI that does nothing. HelpSet hs = null; try { //Create an URL to the help set file. This is the only place //in the program we need to specify a file name. The help set //file contains all there is to know about the help system. URL hsURL = HelpSet.findHelpSet(null, "help/draw-it.hs"); //The HelpSet object "is" the help set file. hs = new HelpSet(null, hsURL); } catch (HelpSetException e) { e.printStackTrace(); } //The HelpBroker contains utility methods for showing appropriate //parts of the help system. HelpBroker hb = hs.createHelpBroker(); //The method "setHelpMenu()" is not yet implemented so we //have to add the help menu the same way as the other menus. JMenu helpMenu = new JMenu("Hjälp"); menuBar.add(helpMenu); JMenuItem content = new JMenuItem("innehåll"); helpMenu.add(content); //The following method call adds an action listener to "content" //that will show the help page indicated by "top". hb.enableHelpOnButton(content, "top", null); //This displays the helpID of the focused child when the user //presses the help key (F1 on windows). hb.enableHelpKey(getRootPane(), "top", null); //CSH contains methods and inner classes that help in creating //context-sensitive help. The inner class used as ActionListener //in the line below displays the helpID of the Component that //sent the ActionEvent, colorHelp.addActionListener(new CSH.DisplayHelpFromSource(hb)); CSH.setHelpIDString(colorHelp, "color"); //This inner class of CSH displays the helpID of the Component //the user clicks on. CSHHelp.addActionListener(new CSH.DisplayHelpAfterTracking(hb)); //Set some helpIDs to illustrate the functionality above. CSH.setHelpIDString(colorButton, "color"); CSH.setHelpIDString(RGBButton, "color"); CSH.setHelpIDString(newButton, "create"); CSH.setHelpIDString(drawArea, "geometry"); setVisible(true); } private void createGUI() { //A very simple GUI that does nothing. menuBar = new JMenuBar(); JMenu menu = new JMenu("Arkiv"); menuBar.add(menu); JToolBar toolBar = new JToolBar(); newButton = new JButton("Ny"); toolBar.add(newButton); toolBar.addSeparator(); colorButton = new JButton("Color..."); toolBar.add(colorButton); RGBButton = new JButton("RGB..."); toolBar.add(RGBButton); colorHelp = new JButton("Help"); toolBar.add(colorHelp); toolBar.addSeparator(); CSHHelp = new JButton(new ImageIcon("csh.gif")); toolBar.add(CSHHelp); drawArea = new JPanel(); drawArea.setBackground(Color.white); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); setJMenuBar(menuBar); getContentPane().add(toolBar, BorderLayout.NORTH); getContentPane().add(drawArea, BorderLayout.CENTER); setSize(400,400); } public static void main(String s[]) { new DrawIt(); } }