> List of tutorials


Fat-Client-Development - Setting the properties of the GUI-Elements

* For this document and all references (links) please obey the hints and regulations concerning copyright, disclaimer and trademarks.

  • The owner of this web-site (www.javascout.biz) is not responsible for the content of web-sites linked within this document or other documents of www.javascout.biz.

  • If this document or other documents of this web-site (www.javascout.biz) infringes rights of third parties and your rights are infringed or you think that rights of others are infringed, please inform the author.
    An e-mail can be sent by clicking onto the 'hungry mailbox' in the upper right corner.

Last revision of this document:
2006-05-05

This step of the tutorial introduces a method to recursively go through all elements making a GUI in Java.
So each element is checked if there are properties defined in the XML-structure. This XML-structure was read in the previous step (JS_FC01f - Base-Class for reading a file with XML-structure).

Then, for elements of type JLabel and JText methods are defined to transfer the properties defined in the XML-structure to the fitting element.
Methods for other element-types (e.g. JButton) will be covered in later steps of this tutorial.

Java allows this algorithm as it has the concept of a 'Container'.
'Container' is a superclassfor all elements that can be a 'parent' of another element. Therefore it is easy to write a method that goes recursively through the the 'tree' of elements which alway starts with an element of type 'JFrame'.

Preface:

This step of the tutorial introduces a convenient method - which is optimized too !
Convenient therefore as only one call of the method within a frame covers each element.
Furthermore all parameters needed are derived from the frame (if it is passed as a correct parameter) where the method is called from. This minimizes the danger of passing wrong parameters (e.g. a wrong name of the element after a 'copy and paste' of an existing element) and 'reading' the wrong properties out of the XML-structure.

Also, a class with static methods is introduced. 'Static methods' can be called without first 'constructing' the class.
This simplifies the coding for methods which do not rely on variables which have to be kept (within the class) after the method finished.

The code written in this tutorial is highly optimized !
It is not essential that you understand the code for getting an idea how Fat-Clients are developed
.

Credits:

Several and none; using recursive structures is a common process - I just applied it for that special case.

Prerequisites:

Create the class JSBS_FrameServices:

This class hold static methods that perform services related to frames.
More explanation follows later when the first method is coded.

top.

Code the method processLanguageDependantElement(. . .):

First a little bit of theory what this method should do:
 * The java elements 'Component' and 'Container' are superclasses for each element that is visible on a GUI.
   A 'Container' can be parent of one or more 'Components' - this reflects the system how a GUI is constructed in Java:
   a Jframe contains one JPanel (the 'ContentPane', a JPanel contains other JPanels, JLabels, JTextFields, JButtons, etc.
   For the documentation of SUN please see http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Container.html.
 * Starting with the 'ContentPane' the algorithm can handle down the structure
   and inspect each element for its type (JPanel, JLabel, JTextField, etc.).
 * If language specific properties need to be set for the identified type, the suitable method,
   which is coded within the class JSBS_XML_DisplayStrings, is called with the identified type as one of the parameters.

As parameters are passed:
 * The class-name of the frame (as String);
   this is one search-argument to find the properties within the XML-structure.
 * The class derived from the JSBS_StartFrame (usually named xxxx_CommandCenter);
   this contains the XML-structure with the language dependant elements.
 * The Java-GUI-element of superclass Container;
   which will be inspected for its type and if it contains 'Components'

top.

Call the recursive method after the frame was build:

The method coded in the previous paragraphs has to be called after the frame is build in the class JS_ErrDB_CommandCenter.

top.

Create the file 'DisplayStrings.xml' and edit the content:

Before we continue with Java-code, the file which should be read has to be created in the folder 'TEXT.en' and edited.

top.

Code the method processJFrame(. . .):

This method belongs to class JSBS_XML_DisplayStrings (package 'js_base.xml').
It searches the XML-structure for the fitting <FrameClass> (the frame was passed as parameter),
then takes the value from <FrameTitle> and
transfers the value (of type String) to the 'Title' of the frame (passed as parameter)

top.

Run the application to see a first result

top.


Next Step: