{"id":553,"date":"2013-07-04T19:50:27","date_gmt":"2013-07-04T19:50:27","guid":{"rendered":"http:\/\/tregner.com\/flare-blog\/?p=553"},"modified":"2013-07-08T16:34:22","modified_gmt":"2013-07-08T16:34:22","slug":"create-a-java-application-that-uses-flare-html5-help","status":"publish","type":"post","link":"https:\/\/tregner.com\/flare-blog\/create-a-java-application-that-uses-flare-html5-help\/","title":{"rendered":"Create a Java Application That Uses Flare HTML5 Help"},"content":{"rendered":"<p>This post describes the creation of a simple Java application and Flare project and HTML5 output to demonstrate opening a Flare HTML5 help topic with a button click or an F1 keypress from a Java application. This is a &#8220;hello world&#8221; level example.<\/p>\n<p>Downloads:<\/p>\n<ul>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/tregner.com\/example-projects\/java-example.flprjzip\">Zipped (Flare-style) Flare project for test HTML5 help<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/tregner.com\/example-projects\/java-app-help.zip\" target=\"_blank\">Zipped copy of generated HTML5 help system for test<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/tregner.com\/example-projects\/JavaAppFlareHtml5Help.zip\" target=\"_blank\">Zipped NetBeans Java application project for test Java application<\/a><\/li>\n<\/ul>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-556\" style=\"font-size: 1rem; line-height: 1;\" alt=\"Java Application and Flare HTML5 Help\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/java-app-and-help.png\" width=\"1920\" height=\"1080\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/java-app-and-help.png 1920w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/java-app-and-help-300x168.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/java-app-and-help-1024x576.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/java-app-and-help-624x351.png 624w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><\/p>\n<p>MadCap provides conceptual information and instructions for programmers and authors about how to configure applications to use context sensitive help with Flare HTML5 outputs. This post covers some of that workflow. The example is less complicated but not as flexible as MadCap&#8217;s suggested workflows. However this post goes into greater detail about how to connect an application to HTML5 help in the context of a Java application.<\/p>\n<p><a href=\"http:\/\/webhelp.madcapsoftware.com\/flare9\/Default.htm#CSH\/HTML5_CSH_Calls\/CSH_Calls_HTML5.htm\" target=\"_blank\">MadCap Software: CSH Calls for HTML5 Output (WebHelp 2.0)<\/a><\/p>\n<p>The example Java and Flare projects are configured such that the application opens a URL for the Flare HTML5 output using the CSHID number in the URL For simplicity, the CSHID number value used is 1 and the topic is Topic.htm (topic.htm in the sample output). Additional calls to open help can be added with the same technique. For more information about CSHID and CSH calls, see the preceding link.<\/p>\n<p>With the arrangement established by the samples in this post, a Flare author would manage the mapping of ID numbers to topics. A programmer would call the same function for every help button click or F1 press and pass the desired ID number. No lookup is necessary on the Java application side. A programmer only needs to know which values to use for actions and UI locations in the application. There is no need to supply a properties file to a programmer with this setup. One possible workflow is the author informs a programmer which IDs to use and the programmer implements those. Another workflow is a programmer assigns IDs and the author updates the Flare project to map those IDs to the topics. Either way the mapping is managed through the Flare HTML5 system.<\/p>\n<p>Other scenarios may be explored in subsequent posts. The Flare documentation describes a workflow in which a copy of a header or a properties file is used by the application so that the application is aware of the mapping between the ID name and number. That workflow adds some flexibility. But that workflow is not demonstrated in this post.<\/p>\n<h2>Create a Java Application with NetBeans<\/h2>\n<p>This example uses NetBeans to create the Java sample. The steps use the IDE options so that those who do not program regularly with Java can replicate the steps more easily. However designing forms in an IDE such as NetBeans involves a reliance on the mechanisms the IDE uses to generate code. For example a NetBeans project with a JFrame form may contain an additional XML file with a <em>.form<\/em> extension to facilitate form building. The Java class for the JFrame is sufficient to run the program. But the <em>.form<\/em> file is required for the form designer in NetBeans.<\/p>\n<p><a href=\"http:\/\/wiki.netbeans.org\/FaqFormFormFile\" target=\"_blank\">NetBeans wiki: What is the .form file?<\/a><\/p>\n<ol>\n<li>Install NetBeans. This example was created on a computer running Windows 8 with Java, the Java Development Kit, and NetBeans installed.\u00a0<a href=\"https:\/\/netbeans.org\/\">https:\/\/netbeans.org\/<br \/>\n<\/a><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/netbeans-ide.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-567\" alt=\"netbeans-ide\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/netbeans-ide.png\" width=\"1936\" height=\"1056\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/netbeans-ide.png 1936w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/netbeans-ide-300x163.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/netbeans-ide-1024x558.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/netbeans-ide-624x340.png 624w\" sizes=\"(max-width: 1936px) 100vw, 1936px\" \/><\/a><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\"><span style=\"line-height: 1.714285714; font-size: 1rem;\">From the menu, select <strong>File<\/strong> &gt; <strong>New Project<\/strong>.\u00a0<span style=\"line-height: 1.714285714; font-size: 1rem;\">The <strong>New Project<\/strong> screen appears.<\/span><\/span><\/span><span style=\"line-height: 1.714285714; font-size: 1rem;\"><br \/>\n<a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-project-screen.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-568\" alt=\"new-project-screen\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-project-screen.png\" width=\"737\" height=\"508\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-project-screen.png 737w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-project-screen-300x206.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-project-screen-624x430.png 624w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/a><br \/>\n<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">Select <strong>Java Application<\/strong>.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\"><span style=\"font-size: 1rem; line-height: 1.714285714;\">Click <strong>Next<\/strong>.<\/span><\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Enter a project name such as <em>JavaAppFlareHtml5Help<\/em>.<br \/>\n<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Click <strong>Finish<\/strong>.<\/span><\/li>\n<\/ol>\n<h2>Add a JFrame Form to the Application<\/h2>\n<p>The window user interface for this example is implemented with a JFrame. The steps which follow describe adding a a JFrame to a Java project in NetBeans.<\/p>\n<ul>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/javax\/swing\/JFrame.html\" target=\"_blank\">Java Platform Reference: Class JFrame<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/tutorial\/uiswing\/components\/frame.html\" target=\"_blank\">The Java Tutorials: How to Make Frames (Main Windows)<\/a><\/li>\n<\/ul>\n<ol>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\"><span style=\"line-height: 1.714285714; font-size: 1rem;\">Right-click the package and select <strong>New<\/strong> &gt; <strong>JFrame form<\/strong>.<br \/>\n<a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-menu-option.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-571\" alt=\"new-jframe-form-menu-option\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-menu-option.png\" width=\"1936\" height=\"1056\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-menu-option.png 1936w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-menu-option-300x163.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-menu-option-1024x558.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-menu-option-624x340.png 624w\" sizes=\"(max-width: 1936px) 100vw, 1936px\" \/><br \/>\n<\/a><\/span><\/span><span style=\"font-size: 1rem; line-height: 1.714285714;\">The <strong>New JFrame Form<\/strong> screen appears.<br \/>\n<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Enter a class name such as <em>JFrameHtml5Example<\/em>.<br \/>\n<\/span><a style=\"color: #0f3647;\" href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-screen.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-572\" alt=\"new-jframe-form-screen\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-screen.png\" width=\"737\" height=\"508\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-screen.png 737w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-screen-300x206.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-form-screen-624x430.png 624w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><\/a><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Click <strong>Finish<\/strong>.<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">The JFrame designer appears in NetBeans.<br \/>\n<a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-in-designer.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-573\" alt=\"new-jframe-in-designer\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-in-designer.png\" width=\"1936\" height=\"1056\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-in-designer.png 1936w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-in-designer-300x163.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-in-designer-1024x558.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/new-jframe-in-designer-624x340.png 624w\" sizes=\"(max-width: 1936px) 100vw, 1936px\" \/><\/a><br \/>\n<\/span><\/li>\n<\/ol>\n<h2>Add a JLabel and a Help JButton to the JFrame<\/h2>\n<ul>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/javax\/swing\/JLabel.html\" target=\"_blank\">Java Platform Reference: Class JLabel<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/javax\/swing\/JButton.html\" target=\"_blank\">Java Platform Reference: Class JButton<\/a><\/li>\n<\/ul>\n<p>The JLabel is just an embellishment for this example to place some text on the JFrame. The JButton provides an interface to click to show a help topic.<\/p>\n<ol>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Drag a JLabel from the palette to the designer. JLabel is located under <strong>Swing Controls<\/strong> on the palette and is indicated as <strong>Label<\/strong>. This and the next step are not necessary to demonstrate opening help.<br \/>\n<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">From the properties screen for the JLabel, change the text to <em>Flare HTML5 Help Example<\/em>.<br \/>\n<\/span><img loading=\"lazy\" class=\"alignnone size-full wp-image-581\" alt=\"label-in-jframe-designer\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/label-in-jframe-designer.png\" width=\"1936\" height=\"1056\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/label-in-jframe-designer.png 1936w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/label-in-jframe-designer-300x163.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/label-in-jframe-designer-1024x558.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/label-in-jframe-designer-624x340.png 624w\" sizes=\"(max-width: 1936px) 100vw, 1936px\" \/><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Drag a JButton from the palette to the designer. JButton is located under <strong>Swing Controls<\/strong> and is indicated as <strong>Button<\/strong>.<br \/>\n<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">From the properties screen for the JButton, change the text to <em>Help<\/em>.<br \/>\n<a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/button-in-jframe-designer.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-584\" alt=\"button-in-jframe-designer\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/button-in-jframe-designer.png\" width=\"1936\" height=\"1056\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/button-in-jframe-designer.png 1936w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/button-in-jframe-designer-300x163.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/button-in-jframe-designer-1024x558.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/button-in-jframe-designer-624x340.png 624w\" sizes=\"(max-width: 1936px) 100vw, 1936px\" \/><\/a><br \/>\n<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Double-click the button in the designer.\u00a0<\/span><span style=\"line-height: 1.714285714; font-size: 1rem;\">The code for the action event appears in the code editor.\u00a0<\/span><span style=\"line-height: 1.714285714; font-size: 1rem;\"><span style=\"line-height: 1.714285714; font-size: 1rem;\">Call a yet-to-be-defined function called <em>showHelp<\/em> and pass a string value of 1.<\/span><\/span>\n<pre class=\"lang:java decode:true\">    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         \r\n        showHelp(\"1\");\r\n    }<\/pre>\n<p>&nbsp;<\/li>\n<\/ol>\n<h2>Add F1 Events<\/h2>\n<p>To create F1 behavior, a handler must be added for every control on the form which should cause help to open when F1 is pressed. In this case the only control to worry about is the JButton since it is the only control which can be active. By default, JLabels cannot be activated. A handler is also added to the JFrame itself.<\/p>\n<ul>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/awt\/event\/KeyListener.html#keyPressed(java.awt.event.KeyEvent)\" target=\"_blank\">Java Platform Reference: keyPressed Method<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/java\/awt\/event\/KeyListener.html#keyPressed(java.awt.event.KeyEvent)\" target=\"_blank\">Java Platform Reference: Class EventHandler<\/a><\/li>\n<li><a style=\"line-height: 1.714285714; font-size: 1rem;\" href=\"http:\/\/docs.oracle.com\/javase\/6\/docs\/api\/constant-values.html\" target=\"_blank\">Java Platform Reference: Constant Values<\/a><\/li>\n<\/ul>\n<ol>\n<li>To add a keyPressed event for the JFrame and the JButton, from the properties screen for each, click the ellipses next to <strong>keyPressed<\/strong> under <strong>Events<\/strong>.\u00a0The <strong>Handlers for keyPressed<\/strong> screen appears. The screen shot shows the screen after the event has been added.<br \/>\n<a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/handlers-for-keypressed-screen.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-589\" alt=\"handlers-for-keypressed-screen\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/handlers-for-keypressed-screen.png\" width=\"314\" height=\"394\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/handlers-for-keypressed-screen.png 314w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/handlers-for-keypressed-screen-239x300.png 239w\" sizes=\"(max-width: 314px) 100vw, 314px\" \/><\/a><\/li>\n<li>Click <strong>Add<\/strong>.<\/li>\n<li>The <strong>Add Handler<\/strong> screen appears.<br \/>\n<a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/add-handler-screen.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-592\" alt=\"add-handler-screen\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/add-handler-screen.png\" width=\"342\" height=\"130\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/add-handler-screen.png 342w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/add-handler-screen-300x114.png 300w\" sizes=\"(max-width: 342px) 100vw, 342px\" \/><\/a><\/li>\n<li>Enter a name such as<em> jFrameKeyPressed<\/em> and click <strong>OK<\/strong>.<\/li>\n<li>The handler code appears in the code editor. Call the yet-to-be-defined <em>showHelp<\/em> method from the handler for the case where F1 is pressed. The constant value for the F1 keycode in Java is 112. Wrap the call to showHelp in a conditional that checks for that value.\n<pre class=\"lang:java decode:true\">    private void jFrameKeyPressed(java.awt.event.KeyEvent evt) {                                  \r\n        if (evt.getKeyCode() == 112){\r\n            showHelp(\"1\");\r\n        }\r\n    }                                 \r\n\r\n    private void jButtonKeyPressed(java.awt.event.KeyEvent evt) {                                   \r\n        if (evt.getKeyCode() == 112){\r\n            showHelp(\"1\");\r\n        }\r\n    }<\/pre>\n<p>&nbsp;<\/li>\n<\/ol>\n<h2>Add Methods to Open Help<\/h2>\n<p>The technique employed in this example relies on a call to a <em>showHelp<\/em> method within every event and handler that should cause help to open. The context for the help comes from the ID passed to <em>showHelp<\/em>. The <em>showHelp<\/em> method appends the ID to a base URL for the help system. The base URL is the path to the main help file followed by <em>#cshid=<\/em>. Once the URL is built, it is passed to a method to open a web page.<\/p>\n<p><a href=\"http:\/\/stackoverflow.com\/questions\/10967451\/open-a-link-in-browser-with-java-button\" target=\"_blank\">Stack Overflow: Open a Link in Browser with Java Button<\/a><\/p>\n<ol>\n<li>Add methods to open a web page from the Java application.\u00a0You can paste these into the class for the JFrame.<\/li>\n<li>\n<pre class=\"lang:java decode:true\">    public void showHelp(String key){\r\n        URI uri;\r\n        try {\r\n            uri = new URI(\"http:\/\/tregner.com\/example-projects\/java-app-help\/java-app-help.htm#cshid=\" + key);\r\n            openWebpage(uri);\r\n        } catch (URISyntaxException ex) {\r\n            Logger.getLogger(JFrameHtml5Example.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n    }\r\n\r\n    \/\/see: http:\/\/stackoverflow.com\/questions\/10967451\/open-a-link-in-browser-with-java-button\r\n    public static void openWebpage(URI uri) {\r\n        Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;\r\n        if (desktop != null &amp;&amp; desktop.isSupported(Desktop.Action.BROWSE)) {\r\n            try {\r\n                desktop.browse(uri);\r\n            } catch (Exception e) {\r\n                e.printStackTrace();\r\n            }\r\n        }\r\n    }\r\n\r\n    public static void openWebpage(URL url) {\r\n        try {\r\n            openWebpage(url.toURI());\r\n        } catch (URISyntaxException e) {\r\n            e.printStackTrace();\r\n        }\r\n    }<\/pre>\n<\/li>\n<li>If the above code is pasted into the class file and there are not imports for the classes on which the methods depend, the<strong> Import Classes<\/strong> screen appears. These are the imports required for the example:\n<pre class=\"lang:java decode:true\">import java.awt.Desktop;\r\nimport java.net.URI;\r\nimport java.net.URISyntaxException;\r\nimport java.net.URL;\r\nimport java.util.logging.Level;\r\nimport java.util.logging.Logger<\/pre>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/import-classes-screen.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-598\" alt=\"import-classes-screen\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/import-classes-screen.png\" width=\"475\" height=\"385\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/import-classes-screen.png 475w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/import-classes-screen-300x243.png 300w\" sizes=\"(max-width: 475px) 100vw, 475px\" \/><\/a><\/p>\n<p>&nbsp;<\/li>\n<li>Click <strong>OK<\/strong>.<\/li>\n<li>Save the project files.<\/li>\n<\/ol>\n<h2>Code the Main Method to Open the JFrame<\/h2>\n<p>Open the java file that contains the main method. For this example, the file is <em>JavaAppFlareHtml5Help.java<\/em>. The main method should create and show an instance of the JFrame. Change the main method to this:<\/p>\n<pre class=\"lang:default decode:true\">    public static void main(String[] args) {\r\n        JFrameHtml5Example frame = new JFrameHtml5Example();\r\n        frame.setVisible(true);\r\n    }<\/pre>\n<p>&nbsp;<\/p>\n<h2>Create a Flare Project to Build the Help<\/h2>\n<p>Create a new Flare project with the Empty template. Use HTML5 as the default target.<\/p>\n<ol>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">Select <strong>File<\/strong> &gt; <strong>New Project<\/strong>. The <strong>Start New Project Wizard<\/strong> appears.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">For the name, enter <em>java-example<\/em>.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">Click <strong>Next<\/strong>.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">Under <strong>Source<\/strong>, select <strong>New from template<\/strong> and select <em>Empty<\/em>.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">Click <strong>Next<\/strong>.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">For the primary target, select <em>HTML5<\/em>.<\/span><\/li>\n<li><span style=\"font-size: 1rem; line-height: 1.714285714;\">Click <strong>Finish<\/strong>.<\/span><\/li>\n<\/ol>\n<p>Add an extra topic named <em>extra-topic.htm<\/em> and set that as the default topic on the HTML5 target. This ensures the default topic is not the topic opened by the application. That demonstrates the application opens a specific topic and not just the default.<\/p>\n<ol>\n<li>Right-click the <strong>Content folder<\/strong> in <strong>Content Explorer<\/strong> and select <strong>New<\/strong> &gt; <strong>Topic<\/strong>. The <strong>Add File<\/strong> screen appears.<\/li>\n<li>In the <strong>File Name<\/strong> field, enter <em>extra-topic<\/em>.<\/li>\n<li>Click <strong>Add<\/strong>.<\/li>\n<li>Save the topic.<\/li>\n<li>In the<strong> Project Organizer<\/strong> within the <strong>Targets<\/strong> folder, double-click the HTML5 target to open it in the Target Editor.<\/li>\n<li>On the <strong>General<\/strong> tab in the <strong>Startup Topic<\/strong> field, select <em>extra-topic<\/em>.<\/li>\n<li>Save the target.<\/li>\n<\/ol>\n<p>Set the topic alias. Open the alias file and assign <em>Topic.htm<\/em> to the identifier in the alias file. The header file will update when the alias file is saved.<\/p>\n<ol>\n<li>From the <strong>Project Organizer<\/strong> within the <strong>Advanced<\/strong> &gt; <strong>CSH<\/strong> folder, double-click the <em>AliasFile.flali<\/em> file. The alias file appears in an editor.<\/li>\n<li>In the alias file editor, navigate to the <em>Topic.htm<\/em> file and right-click the file.<\/li>\n<li>From the menu, select <strong>Assign topic to selected identifier<\/strong>.<\/li>\n<li>Save the alias file.<\/li>\n<li>In the Target Editor for the HTML5 target on the <strong>General<\/strong> tab, change the name of the output file to\u00a0<em>java-app-help<\/em>.<\/li>\n<li>In the Target Editor for the HTML5 target on the <strong>Genera<\/strong>l tab, change the <strong>Startup Topic<\/strong> to <em>extra-topic.htm<\/em>.<\/li>\n<\/ol>\n<p><a href=\"http:\/\/webhelp.madcapsoftware.com\/flare9\/Default.htm#CSH\/Creating_and_Assigning_Identifiers.htm\" target=\"_blank\">MadCap Software: Creating and Assigning Identifiers<\/a><\/p>\n<p>A handful of changes were made to the template for this example. Some of the changes are shown in the screen shot that follows. The order of items in the screen shot is:<\/p>\n<ul>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Project Organizer<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Content Explorer<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">Topic.htm in XML Editor<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">HeaderFile.h in Header Editor<\/span><\/li>\n<li><span style=\"line-height: 1.714285714; font-size: 1rem;\">AliasFile.flali in Alias Editor<\/span><\/li>\n<\/ul>\n<p><a href=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/everything-for-hello-world-csh.png\"><img loading=\"lazy\" class=\"alignnone size-full wp-image-603\" alt=\"everything-for-hello-world-csh\" src=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/everything-for-hello-world-csh.png\" width=\"1936\" height=\"1056\" srcset=\"https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/everything-for-hello-world-csh.png 1936w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/everything-for-hello-world-csh-300x163.png 300w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/everything-for-hello-world-csh-1024x558.png 1024w, https:\/\/tregner.com\/flare-blog\/wp-content\/uploads\/2013\/07\/everything-for-hello-world-csh-624x340.png 624w\" sizes=\"(max-width: 1936px) 100vw, 1936px\" \/><\/a><\/p>\n<h2>Test the Application and Help<\/h2>\n<p>Build the target an place the output somewhere. Adjust the path in the <em>showHelp<\/em> method to reflect the location of the help files.<\/p>\n<pre class=\"lang:default decode:true\">    public void showHelp(String key){\r\n        URI uri;\r\n        try {\r\n            uri = new URI(\"http:\/\/tregner.com\/example-projects\/java-app-help\/java-app-help.htm#cshid=\" + key);\r\n            openWebpage(uri);\r\n        } catch (URISyntaxException ex) {\r\n            Logger.getLogger(JFrameHtml5Example.class.getName()).log(Level.SEVERE, null, ex);\r\n        }\r\n    }<\/pre>\n<p>To run the program from the IDE, with the project open and active, select <strong>Run<\/strong> &gt; <strong>Run Project<\/strong>.<\/p>\n<p>Downloads:<\/p>\n<ul>\n<li><a href=\"http:\/\/tregner.com\/example-projects\/java-example.flprjzip\">Zipped (Flare-style) Flare project for test HTML5 help<\/a><\/li>\n<li><a href=\"http:\/\/tregner.com\/example-projects\/java-app-help.zip\" target=\"_blank\">Zipped copy of generated HTML5 help system for test<\/a><\/li>\n<li><a href=\"http:\/\/tregner.com\/example-projects\/JavaAppFlareHtml5Help.zip\" target=\"_blank\">Zipped NetBeans Java application project for test Java application<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This post describes the creation of a simple Java application and Flare project and HTML5 output to demonstrate opening a Flare HTML5 help topic with a button click or an F1 keypress from a Java application. This is a &#8220;hello world&#8221; level example. Downloads: Zipped (Flare-style) Flare project for test HTML5 help Zipped copy of&hellip; <a class=\"more-link\" href=\"https:\/\/tregner.com\/flare-blog\/create-a-java-application-that-uses-flare-html5-help\/\">Continue reading <span class=\"screen-reader-text\">Create a Java Application That Uses Flare HTML5 Help<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[72,73,53,71,5],"_links":{"self":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/553"}],"collection":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/comments?post=553"}],"version-history":[{"count":86,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/553\/revisions"}],"predecessor-version":[{"id":651,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/posts\/553\/revisions\/651"}],"wp:attachment":[{"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/media?parent=553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/categories?post=553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tregner.com\/flare-blog\/wp-json\/wp\/v2\/tags?post=553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}