?? 制作java應用程序的幫助文件.htm
字號:
Last<BR>目錄建好了以后,我們要在Help目錄下面寫出四個文件:hello.hs,Map.jhm,index.xml以及toc.xml<BR>hello.hs:<BR><?xml
version='1.0' encoding='ISO-8859-1' ?><BR><!DOCTYPE
helpset<BR>PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet
Version
1.0//EN"<BR>"http://java.sun.com/products/javahelp/helpset_1_0.dtd"><BR><BR><helpset
version="1.0"><BR><title>Hello,
JavaHelp</title><BR><maps><BR><mapref
location="Map.jhm"/><BR><homeID>overview</homeID><BR></maps><BR><view><BR><name>TOC</name><BR><label>TOC</label><BR><type>javax.help.TOCView</type><BR><data>toc.xml</data><BR></view><BR><view><BR><name>Index</name><BR><label>Index</label><BR><type>javax.help.IndexView</type><BR><data>index.xml</data><BR></view><BR></helpset><BR>下面是Map.jhm文件的內容:<BR><?xml
version='1.0' encoding='ISO-8859-1' ?><BR><!DOCTYPE
map<BR>PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Map Version
1.0//EN"<BR>"http://java.sun.com/products/javahelp/map_1_0.dtd"><BR><BR><map
version="1.0"><BR><mapID target="overview"
url="Hello/overview.htm" /><BR><mapID target="one"
url="Hello/First/one.htm" /><BR><mapID target="two"
url="Hello/First/two.htm" /><BR><mapID target="three"
url="Hello/Last/three.htm" /><BR><mapID target="four"
url="Hello/Last/four.htm"
/><BR></map><BR>下面是index.xml文件的內容:<BR><?xml
version='1.0' encoding='ISO-8859-1' ?><BR><!DOCTYPE
index<BR>PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Index
Version
1.0//EN"<BR>"http://java.sun.com/products/javahelp/index_1_0.dtd"><BR><BR><index
version="1.0"><BR><indexitem text="The
First?"><BR><indexitem target="one" text="I'm
One"/><BR><indexitem target="two" text="I'm
Second"/><BR></indexitem><BR><indexitem text="The
Last?"><BR><indexitem target="three" text="We're
Third!"/><BR><indexitem target="four" text="We're
Last"/><BR></indexitem><BR><indexitem target="overview"
text="Overview!!!"/><BR></index><BR><BR>下面是toc.xml文件的內容:<BR><?xml
version='1.0' encoding='ISO-8859-1' ?><BR><!DOCTYPE
toc<BR>PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version
1.0//EN"<BR>"http://java.sun.com/products/javahelp/toc_1_0.dtd"><BR><BR><toc
version="1.0"><BR><tocitem image="toplevelfolder"
target="overview" text="Hello, JavaHelp"><BR><tocitem
text="First Stuff"><BR><tocitem target="one" text="The
One"/><BR><tocitem target="two" text="The
Second"/><BR></tocitem><BR><tocitem text="Last
Stuff"><BR><tocitem target="three" text="What's
Third?"/><BR><tocitem target="four" text="The
End"/><BR></tocitem><BR></tocitem><BR></toc><BR>創建好以上四個文件以后,記得把它們放到help目錄下面,<BR>現在需要四個htm文件,把幫助內容寫在htm里面,<BR>Hello/overview.htm<BR>Hello/First/one.htm<BR>Hello/First/two.htm<BR>Hello/Last/three.htm<BR>Hello/Last/four.htm<BR>那么現在Help目錄下的結構就變成了下面一樣:<BR>+
help<BR>hello.hs<BR>index.xml<BR>Map.jhm<BR>toc.xml<BR>+
Hello<BR>overview.htm<BR>+ First<BR>one.htm<BR>two.htm<BR>+
Last<BR>three.htm<BR>four.htm<BR>還記得開始讓你下載的JavaHelp嗎?解包以后在jh1.1.3\demos\bin目錄下面有個hsviewer.jar文件<BR>我們用它來查看幫助文件是否做得完美,將hsviewer.jar加入到classpath里面<BR>假如jh1.1.3解壓到了E:\,<BR>set
classpath=%classpath%;E:\jh1.1.3\demos\bin\hsviewer.jar<BR>然后執行:<BR>java
sunw.demo.jhdemo.JHLauncher<BR>有一個圖形界面出來,按瀏覽按鈕找到Help\hello.hs文件,按display顯示幫助文件。<BR></FONT><FONT
face=arial,sans-serif color=#000000 size=2>helpset顯示如下圖:<BR><IMG
alt="" hspace=0 src="" align=baseline border=0></FONT></P>
<P><FONT face=arial,sans-serif color=#000000
size=2><BR><BR><STRONG><FONT
color=#ff0033><BR>2,將幫助加到你的應用中來。</FONT></STRONG><BR>本質上,將應用程序和HelpSet聯系起來的方法就是<BR>將幫助文件名映射到swing的組件里來。這時你需要jh.jar<BR>這個文件在jh1.1.3\javahelp\lib里面,你必須把它加入classpath<BR>或者是拷貝到jre\lib\ext目錄下。如果你用JBuilder,可以在菜單<BR>Tools的Configure
Libraries里面增加一個Lib,選擇jh.jar,然后在<BR>Project里面選擇使用這個Lib。<BR>javahelp的lib不小,其實核心的三個類HelpSet,
HelpBroker,和CSH<BR>就可以使javahelp運行起來了。<BR>首先導入javahelp的類:<BR>import
javax.help.*;<BR>然后你得找到HelpSet文件,通過包含HelpSet的URL對象<BR>或者使用HelpSet類的findHelpSet方法得到URL對象,<BR>findHelpSet方法通過ClassLoader找到幫助文件。<BR>有了URL對象以后就可以構造一個HelpSet對象了:<BR>import
java.net.*;<BR>...<BR><BR>HelpSet helpset = null;<BR>ClassLoader
loader = null;<BR>URL url = HelpSet.findHelpSet(loader,
"hello.hs");<BR>try {<BR>helpset = new HelpSet(loader, url);<BR>}
catch (HelpSetException e) {<BR>System.err.println("Error
loading");<BR>return;<BR>}<BR>然后你要從helpset得到HelpBroker對象
。<BR>HelpBroker helpbroker =
helpset.createHelpBroker();<BR><BR>最后是幫助跟組件的綁定。<BR>ActionListener
listener = <BR>new
CSH.DisplayHelpFromSource(helpbroker);<BR>overview.addActionListener(listener);<BR><BR><BR><BR>完整代碼如下:<BR>import
javax.swing.*;<BR>import java.awt.*;<BR>import
java.awt.event.*;<BR>import javax.help.*;<BR>import
java.net.*;<BR><BR>public class HelloHelp {<BR>public static void
main(String args[]) {<BR>JFrame frame = new JFrame("Hello,
JavaHelp");<BR>frame.setDefaultCloseOperation(<BR>JFrame.EXIT_ON_CLOSE);<BR>Container
content = frame.getContentPane();<BR><BR>JMenuBar menubar = new
JMenuBar();<BR>JMenu helpMenu = new JMenu("Help");<BR>JMenuItem
overview = new JMenuItem("Overview");<BR>JMenuItem specific = new
JMenuItem("Specific");<BR>helpMenu.add(overview);<BR>helpMenu.add(specific);<BR>menubar.add(helpMenu);<BR>frame.setJMenuBar(menubar);<BR><BR>JButton
button1 = new JButton("The Button");<BR>JButton button2 = new
JButton("Context");<BR><BR>content.add(button1,
BorderLayout.NORTH);<BR>content.add(button2,
BorderLayout.SOUTH);<BR><BR>HelpSet helpset = null;<BR>ClassLoader
loader = null;<BR>URL url = HelpSet.findHelpSet(loader, "hello.hs");
<BR>try {<BR>helpset = new HelpSet(loader, url);<BR>} catch
(HelpSetException e) {<BR>System.err.println("Error
loading");<BR>return;<BR>}<BR><BR>HelpBroker helpbroker =
helpset.createHelpBroker();<BR><BR>ActionListener listener = <BR>new
CSH.DisplayHelpFromSource(helpbroker);<BR>overview.addActionListener(listener);<BR><BR>CSH.setHelpIDString(specific,
"one");<BR>specific.addActionListener(listener);<BR><BR>CSH.setHelpIDString(button1,
"two");<BR>ActionListener tracker = <BR>new
CSH.DisplayHelpAfterTracking(helpbroker);<BR>button2.addActionListener(tracker);<BR><BR>JRootPane
rootpane =
frame.getRootPane();<BR>helpbroker.enableHelpKey(rootpane, "three",
helpset);<BR><BR>frame.setSize(200,
200);<BR>frame.show();<BR>}<BR>}</FONT></P>
<P><FONT face=arial,sans-serif color=#000000
size=2>以上目錄和文件以及程序你可以在http://www.jzventures.com/javahelp.zip下載。<BR></P></FONT></SPAN><BR>
<DIV
style="FONT-SIZE: 14px; LINE-HEIGHT: 25px"><STRONG>作者Blog:</STRONG><A
id=ArticleContent1_ArticleContent1_AuthorBlogLink
href="http://blog.csdn.net/gdsean/"
target=_blank>http://blog.csdn.net/gdsean/</A></DIV>
<DIV
style="FONT-SIZE: 14px; COLOR: #900; LINE-HEIGHT: 25px"><STRONG>相關文章</STRONG></DIV>
<TABLE id=ArticleContent1_ArticleContent1_RelatedArticles
style="BORDER-COLLAPSE: collapse" cellSpacing=0 border=0>
<TBODY>
<TR>
<TD><A
href="http://dev.csdn.net/article/14/article/24/24895.shtm">為自己的系統搞個全文搜索</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/14/article/23/23784.shtm">寫自己的rss</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/14/article/23/23776.shtm">為jive論壇加上投票功能</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/14/article/23/23774.shtm">為jive論壇加上投票功能</A>
</TD></TR>
<TR>
<TD><A
href="http://dev.csdn.net/article/14/article/22/22505.shtm">緩存JSP顯示的html</A>
</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><A name=#Comment></A>
<TABLE cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD>
<TABLE cellSpacing=0 cellPadding=0 width="100%" align=center
bgColor=#006699 border=0>
<TBODY>
<TR bgColor=#006699>
<TD id=white align=middle width=556 bgColor=#006699><FONT
color=#ffffff>對該文的評論</FONT> </TD></TR></TBODY></TABLE>
<DIV align=right><A id=CommnetList1_CommnetList1_Morelink
href="http://comment.csdn.net/Comment.aspx?c=2&s=14697">【評論】</A>
<A id=CommnetList1_CommnetList1_Hyperlink1
href="javascript:window.close();">【關閉】</A>
</DIV><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></FORM><!-- 版權 -->
<HR align=center width=770 noShade SIZE=1>
<TABLE cellSpacing=0 cellPadding=0 width=500 align=center border=0>
<TBODY>
<TR>
<TD vAlign=bottom align=middle height=10><A
href="http://www.csdn.net/intro/intro.asp?id=2">網站簡介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">廣告服務</A> - <A
href="http://www.csdn.net/map/map.shtm">網站地圖</A> - <A
href="http://www.csdn.net/help/help.asp">幫助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">聯系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
height=48 src="制作java應用程序的幫助文件.files/biaoshi.gif" width=40
border=0></A></TD></TR>
<TR>
<TD vAlign=top align=middle>北京百聯美達美數碼科技有限公司 版權所有 京ICP證020026號</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.NET, Inc. All Rights
Reserved</FONT></TD></TR>
<TR>
<TD height=15></TD></TR></TBODY></TABLE><!-- /版權 -->
<SCRIPT>
document.write("<img src=http://count.csdn.net/count/pageview1.asp?columnid=4&itemid=11 border=0 width=0 height=0>");
</SCRIPT>
</BODY></HTML>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -