Creating an 'About dialog'
An elementary part of an application is its 'about' dialog. An 'about dialog' usually is shown when the user likes to know which application is currently running, by whom it was created, which version the user operates, which terms and conditions are connected to usage, etc.
It is common practice to have an item in the help menu of an application such as 'About SimplyHTML' for this purpose. This menu item in application SimplyHTML creates an instance of its AboutBox class.
Class AboutBox
Class AboutBox descends from class JDialog and hosts a number of information panels. In the upper left part, an image associated with the application is shown (see below). Next to the image on the right a number of JLabels have the application name, current release, the author (wow, that's me!) and the application's home page. The name of the application is taken from the constant APP_NAME of class FrmMain.
Below these components, a license panel shows the full text of the GNU General Public License SimplyHTML is distributed under. Finally a close button is displayed at the bottom of the dialog.
AboutBox does not have any other function than to construct itself and to be shown for information. Once the close button is pressed, it is disposed properly. This is ensured by overriding method processWindowEvent and calling enableEvents in the constructor of AboutBox.
Reading an image from the class path
A common way to display an image is to place a JLabel somewhere onto a visible component and associate an image to it. JLabel has a constructor especially for that, which accepts an ImageIcon object as a parameter. The image is taken from the class path of application SimplyHTML, where file ' App.jpg' is distributed together with the applciation's classes in subdirectory 'image '.
Method getResource in the Class object of respective JLabel is used to create an ImageIcon object for file ' App.jpg'. Using the command this.getClass.getResource("image/App.jpg") gets the class object of this JLabel object and finds out from where it was loaded. Calling getResource on this Class object resolves the name given as a parameter to getResource as a relative path to the path where the class was found.