Èç¹ûÄãʹÓùýJBuilder£¬²¢ÇÒ¿´¹ýËüµÄ°ïÖúµÄ»°£¬ Ïë²»ÏëÈÃÄã×Ô¼ºµÄÓ¦ÓóÌÐòÒ²ÓиöÕâôרҵµÄ°ïÖúÄØ£¿ ÊÂʵÉÏ×öÆðÀ´ÊǺܼòµ¥µÄ£¬sunÌṩÁËÒ»¸öJavaHelp¿ÉÒÔ°ïÖúÎÒÃÇ ÊµÏÖÕâ¸öÄ¿µÄ¡£ ʹÓÃjavaHelpΪӦÓÃÌí¼Ó°ïÖúÓÐÁ½¸ö²½Ö裺 1£¬ÖÆ×÷°ïÖúÎļþ(helpSet)¡£
ÏÖÔÚÏÈÈÃÎÒÃÇÀ´ÖÆ×÷helpSet°É£¬´ò¿ªhttp://java.sun.com/products/javahelp/download_binary.html. ÏÂÔØÒ»¸özip°æ±¾µÄJavaHelp£¬Ä¿Ç°×î¸ßºÃÏñÊÇ1.1.3¡£ ¿ªÊ¼ÖÆ×÷Ò»¸öÃûΪ"Hello,JavaHelp"µÄHelpSet,´´½¨Ò»¸öĿ¼£º"help",helpÏÂÃæÔÙ´´½¨Ò»¸öĿ¼"hello" ÔÚhelloĿ¼ÏÂÃæ´´½¨Á½¸öĿ¼"First","Last",½á¹¹ÈçÏ£º + help + Hello + First + Last Ŀ¼½¨ºÃÁËÒÔºó£¬ÎÒÃÇÒªÔÚHelpĿ¼ÏÂÃæÐ´³öËĸöÎļþ£ºhello.hs£¬Map.jhm£¬index.xmlÒÔ¼°toc.xml hello.hs: <?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE helpset PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN" "http://java.sun.com/products/javahelp/helpset_1_0.dtd">
<helpset version="1.0"> <title>Hello, JavaHelp</title> <maps> <mapref location="Map.jhm"/> <homeID>overview</homeID> </maps> <view> <name>TOC</name> <label>TOC</label> <type>javax.help.TOCView</type> <data>toc.xml</data> </view> <view> <name>Index</name> <label>Index</label> <type>javax.help.IndexView</type> <data>index.xml</data> </view> </helpset> ÏÂÃæÊÇMap.jhmÎļþµÄÄÚÈÝ£º <?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE map PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN" "http://java.sun.com/products/javahelp/map_1_0.dtd">
<map version="1.0"> <mapID target="overview" url="Hello/overview.htm" /> <mapID target="one" url="Hello/First/one.htm" /> <mapID target="two" url="Hello/First/two.htm" /> <mapID target="three" url="Hello/Last/three.htm" /> <mapID target="four" url="Hello/Last/four.htm" /> </map> ÏÂÃæÊÇindex.xmlÎļþµÄÄÚÈÝ£º <?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE index PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN" "http://java.sun.com/products/javahelp/index_1_0.dtd">
<index version="1.0"> <indexitem text="The First?"> <indexitem target="one" text="I'm One"/> <indexitem target="two" text="I'm Second"/> </indexitem> <indexitem text="The Last?"> <indexitem target="three" text="We're Third!"/> <indexitem target="four" text="We're Last"/> </indexitem> <indexitem target="overview" text="Overview!!!"/> </index>
ÏÂÃæÊÇtoc.xmlÎļþµÄÄÚÈÝ£º <?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE toc PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN" "http://java.sun.com/products/javahelp/toc_1_0.dtd">
<toc version="1.0"> <tocitem image="toplevelfolder" target="overview" text="Hello, JavaHelp"> <tocitem text="First Stuff"> <tocitem target="one" text="The One"/> <tocitem target="two" text="The Second"/> </tocitem> <tocitem text="Last Stuff"> <tocitem target="three" text="What's Third?"/> <tocitem target="four" text="The End"/> </tocitem> </tocitem> </toc> ´´½¨ºÃÒÔÉÏËĸöÎļþÒԺ󣬼ǵðÑËüÃǷŵ½helpĿ¼ÏÂÃæ£¬ ÏÖÔÚÐèÒªËĸöhtmÎļþ£¬°Ñ°ïÖúÄÚÈÝдÔÚhtmÀïÃæ£¬ Hello/overview.htm Hello/First/one.htm Hello/First/two.htm Hello/Last/three.htm Hello/Last/four.htm ÄÇôÏÖÔÚHelpĿ¼ÏµĽṹ¾Í±ä³ÉÁËÏÂÃæÒ»Ñù£º + help hello.hs index.xml Map.jhm toc.xml + Hello overview.htm + First one.htm two.htm + Last three.htm four.htm »¹¼ÇµÃ¿ªÊ¼ÈÃÄãÏÂÔØµÄJavaHelpÂ𣿽â°üÒÔºóÔÚjh1.1.3\demos\binĿ¼ÏÂÃæÓиöhsviewer.jarÎļþ ÎÒÃÇÓÃËüÀ´²é¿´°ïÖúÎļþÊÇ·ñ×öµÃÍêÃÀ£¬½«hsviewer.jar¼ÓÈëµ½classpathÀïÃæ ¼ÙÈçjh1.1.3½âѹµ½ÁËE:\, set classpath=%classpath%;E:\jh1.1.3\demos\bin\hsviewer.jar È»ºóÖ´ÐУº java sunw.demo.jhdemo.JHLauncher ÓÐÒ»¸öͼÐνçÃæ³öÀ´£¬°´ä¯ÀÀ°´Å¥ÕÒµ½Help\hello.hsÎļþ£¬°´displayÏÔʾ°ïÖúÎļþ¡£ helpsetÏÔʾÈçÏÂͼ£º

2£¬½«°ïÖú¼Óµ½ÄãµÄÓ¦ÓÃÖÐÀ´¡£ ±¾ÖÊÉÏ£¬½«Ó¦ÓóÌÐòºÍHelpSetÁªÏµÆðÀ´µÄ·½·¨¾ÍÊÇ ½«°ïÖúÎļþÃûÓ³Éäµ½swingµÄ×é¼þÀïÀ´¡£ÕâʱÄãÐèÒªjh.jar Õâ¸öÎļþÔÚjh1.1.3\javahelp\libÀïÃæ£¬Äã±ØÐë°ÑËü¼ÓÈëclasspath »òÕßÊÇ¿½±´µ½jre\lib\extĿ¼Ï¡£Èç¹ûÄãÓÃJBuilder£¬¿ÉÒÔÔڲ˵¥ ToolsµÄConfigure LibrariesÀïÃæÔö¼ÓÒ»¸öLib£¬Ñ¡Ôñjh.jar£¬È»ºóÔÚ ProjectÀïÃæÑ¡ÔñʹÓÃÕâ¸öLib¡£ javahelpµÄlib²»Ð¡£¬ÆäʵºËÐĵÄÈý¸öÀàHelpSet, HelpBroker,ºÍCSH ¾Í¿ÉÒÔʹjavahelpÔËÐÐÆðÀ´ÁË¡£ Ê×Ïȵ¼ÈëjavahelpµÄÀࣺ import javax.help.*; È»ºóÄãµÃÕÒµ½HelpSetÎļþ£¬Í¨¹ý°üº¬HelpSetµÄURL¶ÔÏó »òÕßʹÓ**elpSetÀàµÄfindHelpSet·½·¨µÃµ½URL¶ÔÏó£¬ findHelpSet·½·¨Í¨¹ýClassLoaderÕÒµ½°ïÖúÎļþ¡£ ÓÐÁËURL¶ÔÏóÒÔºó¾Í¿ÉÒÔ¹¹ÔìÒ»¸öHelpSet¶ÔÏóÁË£º 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; } È»ºóÄãÒª´ÓhelpsetµÃµ½HelpBroker¶ÔÏó ¡£ HelpBroker helpbroker = helpset.createHelpBroker();
×îºóÊǰïÖú¸ú×é¼þµÄ°ó¶¨¡£ ActionListener listener = new CSH.DisplayHelpFromSource(helpbroker); overview.addActionListener(listener);
ÍêÕû´úÂëÈçÏ£º 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(menubar);
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 (HelpSetException 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, 200); frame.show(); } }
ÒÔÉÏĿ¼ºÍÎļþÒÔ¼°³ÌÐòÄã¿ÉÒÔÔÚhttp://www.jzventures.com/javahelp.zipÏÂÔØ¡£

|