Help screens are a necessity for making any application user-friendly. This article will show how the JEditorPane and JFrame classes, along with HTML files, can be used to create help windows for any Java application. This is a project-oriented article that will walk the reader through all the code needed for development. Some familiarity with Java is assumed.
The class we’ve created is a very basic use of JEditorPane to display HTML help files. There are numerous ways in which it could be improved and I will make a few suggestions here. Buttons to navigate to previously visited URLs might be helpful. A menubar might provide a more elegant means of navigation.
Remember also that this class retains all the functionality of its parent. If you are not satisfied with the size of the window, you can simply use the “setSize” method inherited from the JFrame class. Likewise with methods such as “setBackground”. Furthermore, the functionality of this class could be extended by deriving other classes from it. That said, it is best to remember that Java only supports HTML version 3.2, and this fact will certainly restrict what can be achieved.
Finally, the way in which exceptions are handled could be improved. In a follow-up article we will show how to construct a generic class to handle exceptions thrown by any Java application.
To summarize, we have presented a class that creates a basic help window and can be incorporated into any Java application. In so doing we have achieved one of the goals of object-oriented programming – namely creating a reusable class.