Help files for making Java applications

zhaozj2021-02-11  179

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: 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> below is the content of the map.jhm file: < XML Version = '1.0' Encoding = 'ISO-8859-1'?> <! doctype mappublic "- // 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 =" O Ne "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 "</p> <p>/> </ map> The following is the content of the index.xml file: <? XML Version = '1.0' encoding = 'ISO-8859-1'?> <! doctype indexpublic "- // sun microsystems incap //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 !!!" /> <=View !!! "/> < / index> The following is the content of the Toc.xml file: <? XML Version = '1.0' Encoding = 'ISO-8859-1'?> <! doctype TOCPUBLIC "- // 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" /> </ Toctem> <Toctem text = " Last Stuff> <Toctem Target = "Three" text = "W HAT'S THIRD? "/> <Toctem Target =" FORR "text =" the end "/> </ TOCITEM> </ Toctem> </ TOC> After the above four files, remember to put them below the HELP directory, Now you need four HTM files,</p> <p>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.</p> <p>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 ();}}</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-5767.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="5767" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.048</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = '6mKUHoB_2BYM97_2FaLke22NnuZZBVFeWqPrtKKCBwzgRKEJrRSVIEuJf1e1feVDzn6BziIaStYZ_2F0r5yUBTWo3rkQ_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>