注重:HTML 呈现引擎是一个 JRE 组件,且不是 JavaHelp 的一部分,因此呈现根据所用的 Java 的版本会有所变化。呈现引擎只显示 HTML 3.2 (带一些 4.0 版本的功能特点)。然而,它确实包含对 CSS1 样式表的支持。示例代码 1: welcome.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <TITLE> Help Overview </TITLE> </HEAD> <BODY BGCOLOR="#ffffff"> <H1>My Sample Online Help</H1> This help system is organized into the following main
topics. You can access these topics directly from the
Help menu. <p> <table width=98% border=0 cellpadding=5> <tr valign="top"> <td width=30%><A HREF="manager.html">Managing Projects</A> </td> <td width=70%> How to create and use projects and
portfolios </td> </tr> <tr valign="top"> <td width=30%><A HREF="debug.html">Debugging Projects</A> </td> <td width=70%> How to debug Java programs </td> </tr> <tr valign="top"> <td width=30%><A HREF="profile.html">Profiling Projects</A> </td> <td width=70%> How to analyze the performance of
Java programs </td> </tr> </table> </ul> <hr> <pre> <font size="-1"> Some Copyright Information Goes Here! </font> </pre> <hr> </BODY> </HTML>
<?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE helpset PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 2.0//EN" "../dtd/helpset_2_0.dtd"> <helpset version="1.0"> <!-- title --> <title>My Sample Help - Online</title> <!-- maps --> <maps> <homeID>top</homeID> <mapref location="Map.jhm"/> </maps> <!-- views --> <view> <name>TOC</name> <label>Table Of Contents</label> <type>javax.help.TOCView</type> <data>SampleTOC.xml</data> </view> <view> <name>Index</name> <label>Index</label> <type>javax.help.IndexView</type> <data>SampleIndex.xml</data> </view> <view> <name>Search</name> <label>Search</label> <type>javax.help.SearchView</type> <data engine="com.sun.java.help.search.DefaultSearchEngine"> JavaHelpSearch </data> </view> <presentation default="true" displayviewimages="false"> <name>main window</name> <size width="700" height="400" /> <location x="200" y="200" /> <title>My Sample Help - Online</title> <image>toplevelfolder</image> <toolbar> <helpaction>javax.help.BackAction</helpaction> <helpaction>javax.help.ForwardAction</helpaction> <helpaction>javax.help.SeparatorAction</helpaction> <helpaction>javax.help.HomeAction</helpaction> <helpaction>javax.help.ReloadAction</helpaction> <helpaction>javax.help.SeparatorAction</helpaction> <helpaction>javax.help.PrintAction</helpaction> <helpaction>javax.help.PrintSetupAction</helpaction> </toolbar> </presentation> <presentation> <name>main</name> <size width="400" height="400" /> <location x="200" y="200" /> <title>My Sample Help - Online</title> </presentation> </helpset> 正如您在示例代码 2 中所看到的,每个窗口都是由其自己的 <presentation> 标签所定义。 presentation 标签包括:
<?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="toplevelfolder" url="images/toplevel.gif" /> <mapID target="top" url="help/welcome.html" /> <mapID target="intro" url="help/welcome.html" /> <mapID target="start" url="help/start.html" /> <mapID target="overview" url="help/welcome.html" /> <mapID target="one" url="help/start.html" /> <mapID target="two" url="help/start.html" /> <mapID target="bean.story" url="help/welcome.html" /> <mapID target="bean.story" url="help/start.html" /> <mapID target="bean.story" url="help/welcome.html" /> </map>
<?xml version='1.0' encoding='ISO-8859-1' ?> <!DOCTYPE toc PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 2.0//EN" "../dtd/toc_2_0.dtd"> <toc version="2.0"> <tocitem text="My Sample Help" image="toplevelfolder"> <tocitem text="Introduction to Sample Online Help" target="intro"/> <tocitem text="Tutorial" target="start" eXPand="true"> <tocitem text="Welcome" target="overview"/> <tocitem text="Tutorial One: Help One" target="one"/> <tocitem text="Tutorial Two: Help Two" target="two"/> </tocitem> <tocitem text="Beans In IDE" target="bean.story"/> <tocitem text="Beans In IDE - in SecondaryWindow" target="bean.story" // presentationtype="javax.help.SecondaryWindow" presentationname="main"/> <tocitem text="Beans In IDE - in Popup" target="bean.story" presentationtype="javax.help.Popup"/> </tocitem> </toc>示例目录的运行结果如图 2 所示。
<?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=".prof extension (profile data)" target="prof.profile"/> <indexitem text="accelerators (keyboard), see 'keyboard commands'"/> <indexitem text="adding an existing project" expand="false"> <indexitem text="naming the project" target="proj.importDirectory"/> <indexitem text="naming the storage directory" target="proj.importdirectory"/> <indexitem text="procedures for" target="proj.importproject2"/> </indexitem> <indexitem text="arguments" expand="false"> <indexitem text="passing" target="debug.arguments"/> <indexitem text="specifying" target="debug.arguments"/> </indexitem> <indexitem text="beans" expand="false"> <indexitem text="adding existing sources to a bean project" target="proj.existingbeans"/> <indexitem text="changing bean file status" target="proj.existingbeans"/> <indexitem text="creating a bean project" target="proj.beansproject"/> <indexitem text="removing existing sources from a bean project" target="proj.existingbeans"/> </indexitem> </index>
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("sample.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(); } } 实验该代码的最简单的方法是将 HelpMenu.java 拷贝至 c:/myhelp下。编译并运行它。假如一切正常,您会看到类似图 5 的情况。假如单击帮助主题( Help Topics), 那么就会出现图 4 中的帮助信息窗口。
新闻热点
疑难解答