If you have used JBuilder, and you can read it, you don't want your own app to have such a professional help? In fact, it is very simple. Sun offers a JavaHelp to help us achieve this. There are two steps to add help with JavaHelp to add help: 1. Making a help file (Helpset). Let us first make our help, open http://java.sun.com/products/javahelp/download_binary.html. Download a ZIP version of JavaHelp, the highest seems to be 1.1.3.
Start making a Helpset called "Hello, Javahelp", create a directory: "Help", then create a directory "Hello" under the Hello directory, "Last", the structure is as follows: After the Help Hello First Last directory, we must write four files below the Help directory: hello.hs, map.jhm, index.xml, and Toc.xmlhello.hs: XML Version = '1.0' encoding = 'ISO-8859-1'?> hello, javahelp title> overview homeid> maps> < Name> TOC Name> TOC label> javax.help.tocview type> toc.xml data> view> index Name> index label> javax.help.indexView type> index.xml data> view> helpset> below is the content of the map.jhm file: < XML Version = '1.0' Encoding = 'ISO-8859-1'?>
/> map> The following is the content of the index.xml file: XML Version = '1.0' encoding = 'ISO-8859-1'?> indexItem> indexItem> <=View !!! "/> < / index> The following is the content of the Toc.xml file: XML Version = '1.0' Encoding = 'ISO-8859-1'?> "TOC VERSION =" 1.0 "> Toctem> TOCITEM> Toctem> TOC> After the above four files, remember to put them below the HELP directory, Now you need four HTM files,
Write the help content in htm, hello / overview.htmhello / first / one.htmhello / first / two.htmhello / last / threetm then now the structure in the Help directory becomes the same : Helphello.hsindex.xmlmap.jhmtoc.xml hellooverview.htm firstthree.htmtwo.htm lastthree.htmfour.htm Remember the javahelp that started to download? After unpacking, there is a hsviewer.jar file below in the JH1.1.3 / DEMOS / BIN directory. We use it to see if the help file is perfect, add hsviewer.jar to classpath, if jh1.1.3 is decompressed to E: /, SET ClassPath =% classpath%; E: /JH1.1.3/Demos/bin/hsviewer.jar then execute: java sunw.demo.jhdemo.jhlauncher has a graphical interface, press the browse button to find the help / hello.hs file, press DISPLAY Display help files. The Helpset is shown below: 2, will help add it in your application. Essentially, the method of linked applications and helpset is to map the help file name to the Swing component. At this time, you need JH.jar this file in JH1.1.3 / javahelp / lib, you must add it to ClassPath or copy it to the jre / lib / ext directory. If you use jbuilder, you can add a libraries in the Menu Tools, select Jar, then select this lib in the Project. Javahelp's lib is not small, in fact, three types of Helpset, HelpBroker, and CSH can run Javahelp. First introduced Javahelp class: import javax.help. *; Then you have to find the Helpset file, get the URL object by containing the URL object containing the Helpset or the FindHelpset method using the Helpset class, find the help file through ClassLoader. With the URL object, you can construct a Helpset object: import java.net. *; ... helpset helpset = null; classloader loader = null; URL URL = helpset.findhelpset (Loader, "Hello.hs"); try {Helpset = New Helpset (Loader, URL);} catch (HelpseTexception E) {system.err.println ("Error Loading"); return;} Then you have to get a HelpBroker object from Helpset. Helpbroker helpbroker = helpset.createhelpbroker (); Finally, it is the binding of the components.
ActionListener listener = new CSH.DisplayHelpFromSource (helpbroker); overview.addActionListener (listener); complete code as follows: import javax.swing *; import java.awt *; import java.awt.event *; import javax.help.... *; import java.net *;. public class HelloHelp {public static void main (String args []) {JFrame frame = new JFrame ( "Hello, JavaHelp"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); Container content = frame .getContentPane (); JMenuBar menubar = new JMenuBar (); JMenu helpMenu = new JMenu ( "Help"); JMenuItem overview = new JMenuItem ( "Overview"); JMenuItem specific = new JMenuItem ( "specific"); helpMenu.add ( Overview); helpMenu.add (Specific); menubar.add (helpmenu); frame.setjmenubar; jButton Button1 = New jButton ("The button); jButton Button2 = New JButton (" context "); content.add (button1, BorderLayout.NORTH); content.add (button2, BorderLayout.SOUTH); HelpSet helpset = null; ClassLoader loader = null; URL url = HelpSet.findHelpSet (loader, "hello.hs"); try {helpset = new Helpset (Loader, URL);} catch (Helpsete) xception e) {System.err.println ( "Error loading"); return;} HelpBroker helpbroker = helpset.createHelpBroker (); ActionListener listener = new CSH.DisplayHelpFromSource (helpbroker); overview.addActionListener (listener); CSH.setHelpIDString ( specific, "one"); specific.addActionListener (listener); CSH.setHelpIDString (button1, "two"); ActionListener tracker = new CSH.DisplayHelpAfterTracking (helpbroker); button2.addActionListener (tracker); JRootPane rootpane = frame.getRootPane ( ); HelpBroker.enableHelpKey (Rootpane, "Three", Helpset; Frame.SetSize (200); frame.show ();}}