|
|
|
Last
revision of this document: |
This
step of the tutorial deals with the universal structure for
parameters.
In this structure values for general purposes are
held while the application is running.
For a detailed description
of the values please see the Code
for JSBS_UniversalParameters.
Constants are coded in a
separate 'Interface'; please see Code
for JSBS_UniversalParameters_Constants.
Within
this step, code for the following tasks is developed:
* At the
'construction' of this class, the subdirectory where the file for the
application resides is determined.*
The language-code, passed as a parameter when the application is
started, is stored in the relevant variable and used for startup
messages.* Relatively to this directory, the
subdirectories for language dependant text, graphics and parameters
for access to database or Java-Application-Server (JAS) are build
(see Directory
Architecture).
Preface:The
code written in this tutorial is far away from being
optimized.
Emphasis of this tutorial is to develop the application
in small steps where the completion of each step allows the
application to be run eror-free and showing the result aimed by the
step.
Therefore the code is written to be understandable in favor
of being optimized.
Credits:None
- that system was developed by myself ;-).
JS_FC01d
- Create and code the class for the GUI
completed - and its
prerequisites too.
Create
the interface JSBS_UniversalParameters_Constants:Right
click onto the project 'JS_Base' and select
>New>Interface.
Enter
the Package (js_base.structures),
the (Interface-)Name (JSBS_UniversalParameters_Constants)
and click the [ Finish ] button.
Eclipse
has already generated a template and the individual code can be
entered.
For a listing of the code please refer to
Code
for JSBS_UniversalParameters_Constants.
Recommendation:
As typing the whole interface
might be boring now, just create the interface and type the
values whenever you get an error because a value is used and
does not exist by then.
Create
the class JSBS_UniversalParameters:The
number of screenshots for repeating steps will be reduced
significantly from now on.
If you feel insecure with the textual
descriptions please go back to the previous steps or work through the
tutorial for practising.
JS_Base02
- DataBase-Loader with a GUI
Right
click onto the project 'JS_Base' and select
>New>Class
Enter
the Package (js_base.structures),
the (Class-)Name (JSBS_UniversalParameters)
select (o) public,
do not check any boxes,
leave
the default Superclass (java.lang.Object),
[
Add ] Interfaces
(JSBS_UniversalParameters_Constants)
and click the [ Finish ]
button.
Eclipse
has already generated a template and the individual code can be
entered.
For a listing of the code please refer to
Code
for JSBS_UniversalParameters.
Recommendation:
As typing the whole class might be
boring now, just create the class and type the following
methods.
Code the variables as needed for the listed methods./*
Constructor of the class */ public
JSBS_UniversaParameter(String
parmLanguageCode) {
. . . . . . . . . public
void buildDirectoryNames() {.
. . . . . . . . public
void buildLanguageDependantDirectoryNames(String
parmstrLanguageCode) {
Incorporate
the class JSBS_UniversalParameters into the base-frame:The
structure will be used for a 'CommandCenter' of any application.
So
the structure is defined as a variable in the class
JSBS_StartFrame.package
public
classjs_base.frame;
import
javax.swing.*;
import
js_base.structures.*;
.
. . . . . . . . JSBS_StartFrame
JFrame {
public
JSBS_UniversalParameter
structJSBS_UniversalParameter;
}
Introduce
a method which contains the code to be performed before the frame is
build:The
construction of the structure is not in the base-class
(
JSBS_StartFrame)
but in the class (JS_ErrDB_CommandCenter)
of the project (JS_FC01).
(This is done, because in my impression
it makes the flow of code easier understandable than it would be in
the base-class.
Kurt, 2006-05-19).
As
mentioned earlier, code to be performed in the class is split into 3
methods:
* do be done before the frame is build,
* build and
display the frame and
* do be done after the frame is build and
displayed.
As the construction of the parameter-structure
(JSBS_UniversalParameters)
is a basic issue, it has to be done before the frame is build.
The
construction is done in the method , which then is called in the
constructor of JS_ErrDB_CommandCenter.
Do
not worry as you get an error for the undeclared parameter
parmstrLanguageCode
- this will be corrected in the next paragraph ! package
js_errdb.clientframes;
import
java.awt.*; import
javax.swing.*;
import
js_base.frame.JSBS_StartFrame*;
import
js_base.structures.*;
.
. . . . . . . . .
. . . . . . . . public
JS_ErrDB_CommandCenter(String
parmstrLanguageCode){
super(); initialize_before_frame(String
parmstrLanguageCode);
initialize_frame;
}
.
. . . . . . . . .
. . . . . . . . return
pnl_Main;
}
private
void initialize_before_frame(String
parmstrLanguageCode) {
structJSBS_UniversalParameter
=
}new
JSBS_UniversalParameter(parmstrLanguageCode);
private
void initialize_frame()
{
setVisible(true);
}.
. . . . . . . .
.
. . . . . . . .
Getting
the language used during start-up of the application as a parameter:To
have a language defined as long as the user - and her or his
preferred language - is not known, the code for language in which
text-elements are displayed during the start-up is passed as a
parameter.
This parameter is derived in the main-method
and passed as a parameter to the constructor of
JS_ErrDB_CommandCenter.
Please
obey that also the constructor of the class is changed to accept the
parameter..
. . . . . . . . .
. . . . . . . . public
JS_ErrDB_CommandCenter(String
parmstrLanguageCode){
super(); initialize_before_frame(String
parmstrLanguageCode);
initialize_frame;
}
.
. . . . . . . . .
. . . . . . . . public
static void main(String[]
args) {
String
locstrLanguageCode = „“;
if (args.length
> 0) locstrLanguageCode =
args[0]; }try
{
JS_ErrDB_CommandCenter
a JS_ErrDB_CommandCenter
=
new JS_ErrDB_CommandCenter(locstrLanguageCode);
}
catch(Throwable
exc) {
System.out.println(„Exception
occured in main() of
JS_ErrDB_CommandCenter“);
exc.printStackTrace(System.out);
}
Next
Step:As
we know the directory where the language-dependant text-elements are
stored, the xml-formatted file with the text for the GUI-elements
will be read and stored in the memory.
To do so, the classes and
methods of the Document-Object-Model (DOM) will be used.
JS_FC01f
- Base-Class for reading a file with XML-structure.