|
Last
revision of this document: |
This document lists the steps (with links to more detailed descriptions and sample code) to develop a Start-Frame as Command-Center to start Task-Frames to perform Business-Tasks.
Shortcut:This
document covers the following steps:
Step
by step instructions for developing a Fat-Client application with
the sections:
* Create the
class,
* Code
the 'Constructor' and call it in the 'main()' method,
* Define
the language dependant GUI-elements and add the code to display
it,
* Define
the list with displayed and internal codes for the Business Tasks
and add the code to display it,
* Reacting
to the button-click and open the Task-Frame,
* Loading
the parameters for database access and writing the XML-structure
with the parameters,
Credits:To
many to list; please see the linked documents with the detailed
descriptions.
Aside,
that the Eclipse
workbench with the plugin for the Visual
Editor (VE) has to be installed,
the preparation
is described here.
Step
by step instructions:Create
the classA
more detailed description with screenshot is in the document JS_FC01d
– Create and code the class for the GUI.
In
catchwords:
* .Right
click onto the 'Project' and select
>New>Other...
* In
the following window expand 'Java' (if not alredy done), select
>Visual
Class and
click the [ Next
> ] button.
* Enter
the Package (xxx_project_xxx.clientframes),
the (Class-)Name
(XXX_Project_XXX_CommandCenter)
and
the
Superclass (js_base.frame.JSBS_StartFrame).
Check
[ ] public static void main(String[] args) and click the
[ Finish ] button
Code
the 'Constructor' and call it in the 'main()' methodThe
following step assumes, that the stardard layout (as defined in the
inherited class JSBS_StartFrame)
should be used.
To
keep the code clearly arranged, the constructor just calls three
methods with the consecutive commands.
The parameter passed
(language used during start-up) will be used in one of the following
steps.public
class JS_ProjAssist_CommandCenter
extends JSBS_StartFrame {/*
*
-------------------------------
* Constructor of the class
*/public
JS_ProjAssist_CommandCenter(String
parmstrLanguageCode){
super(); initialize_before_frame(parmstrLanguageCode);
initialize_frame(); initialize_after_frame(); }
/*
*
-------------------------------
* Method with code to be
executed before the GUI is build */ private
void initialize_before_frame(String
parmstrLanguageCode) { } /*
*
-------------------------------
* Method with code to
construct and display the GUI (Graphic User Interface) */private
void initialize_frame()
{
setVisible(true);
setSize(600,
400);/* Use
the standard GUI-layout (without currency-selection)
* as
defined in the inherited class (JSBS_StartFrame).
*/
setContentPane(get_pnl_Main()); } /*
*
-------------------------------
* Method with code to be
executed after the GUI is build */private
void initialize_after_frame()
{
} public
static void main(String[]
args) {
To
be able to start an application, a main()
- method is requiered: public
static void main(String[]
args) {
String
locstrLanguageCode = "";
if (args.length
> 0) locstrLanguageCode =
args[0]; }try
{
JS_ProjAssist_CommandCenter
aJS_= ProjAssist_CommandCenter
new
JS_(locstrLanguageCode);ProjAssist_CommandCenter
}
catch(Throwable
exc) {
System.out.println("Exception
occured in main() of
JS_ProjAssist_CommandCenter");
exc.printStackTrace(System.out);
}
To
verify, run the application and you should get a frame like
that:
There
is not text visible yet as the text is imported from a language
dependant external file.
That will be covered in the next step.
Define
the language dependant GUI-elements and add the code to display itThe
following step assumes, that the stardard layout (as defined in the
inherited class JSBS_StartFrame)
should be used.
The
file with the xml-structure containing the language dependent
GUI-elements are in the directory 'TEXT' enhanced with the ISO-code
for the language (e.g. 'TEXT.en').
For the theory of the
directories containing 'parameters' please see the document Directory
Architecture.
A
more detailed description with screenshot how to create directory and
file are in the documents JS_FC01g –
Setting the properties of the GUI-elements and
JS_FC01h
– Setting the properties of the GUI-elements, Part
2.
Additionally,
Structure
of the xml-file with language-dependant text-elements for the
user-interface (DisplayStrings.xml in directory TEXT.en)
gives
a theoretical background.
In
catchwords:
* Right
click onto the 'Project' and select >New>Folder.
* Enter
the Folder Name (TEXT.en)
(obey the case, please !) and
click the [ Finish ] button.
* Right
click onto the just created folder and select >New>File.
* Enter
the File Name (DisplayStrings.xml)
and click the [ Finish ] button.
* Copy the
xml-structure from here
into the
empty file.
To
import more classes from the package
js_base.frame,
the fully qualified class StartFrame
has to be changed to a wildcard and some more packages have to be
imported.import
js_base.frame.*;
(instead
of import)
js_base.frame.;StartFrame
import
js_base.structures.*;import
js_base.xml.*;
The
structure with the language dependent GUI-elements is loaded very
early within the application:
Before it can be loaded, the
Universal Parameters have to be 'constructed' as they contain the
folder (directory) where the language dependent elements
reside. private
void initialize_before_frame(String
parmstrLanguageCode) {/* Initialize
the structure with the set of parameters
* (defined in
the inherited class JSBS_StartFrame).
*/
structJSBS_UniversalParameters
= new
JSBS_UniversalParameters(parmstrLanguageCode);/* Initialize
the structure with the language dependent GUI-element
* (defined
in the inherited class JSBS_StartFrame).
* This also
loads the structure from the file.
*/
structJSBS_XML_DisplayStrings
= new
JSBS_XML_DisplayStrings( }structJSBS_UniversalParameters);
/* Verify
if the class was constructed without an error. */
if
(structJSBS_XML_DisplayStrings.StatusCode
!=
JSBS_XML_Constants.CONST_OK)
{
System.out.println("Error
while building 'structJSBS_XML_DisplayStrings'; StatusCode: "
+
(new
Integer(structJSBS_XML_DisplayStrings.StatusCode)).toString());
System.exit(structJSBS_XML_DisplayStrings.StatusCode);
}
After
the GUI-elements are created, the text is assigned to it. private
void initialize_after_frame()
{/* Assign
the language dependent text to the GUI-elements. }
* The
method used is defined in the imported library JSBS_Base.
*/
JSBS_FrameServices.processLanguageDependantElements(this);
As
the application expects the language code as a parameter, this has to
be passed.
To do so, the parameter has to be entered on the tab
'Arguments' when the application is started out of Eclipse:
To
verify, run the application and you should get a frame like
that:
The
fields with the dotted lines are context sensitive and are not filled
by the elements out of the file with the xml-structure.
Define
the list with displayed and internal codes for the Business Tasks and
add the code to display itThe
following step assumes, that the stardard layout (as defined in the
inherited class JSBS_StartFrame)
should be used.
The
file with the xml-structure containing the language dependent
GUI-elements are in the directory 'TEXT' enhanced with the ISO-code
for the language (e.g. 'TEXT.en'). This directory was already created
in the previous step.
For the theory of the directories containing
'parameters' please see the document Directory
Architecture.
A
more detailed description with screenshots about the idea of the
'Task-tree' is in the document Structure
of the xml-file with the list of Tasks for the application (Tasks.xml
in directory TEXT.en).
In
catchwords:
* Right
click onto the folder TEXT.en
and select >New>File.
* Enter
the File Name (Tasks.xml)
and click the [ Finish ] button.
* Copy the
xml-structure from here
into the
empty file.
The
XML-structure with the Business-Task is loaded immedeiately after the
structure with the text for the language dependent GUI-elements.
This
is done because the GUI-element that displays the information about
Business Tasks has to be created and filled with content before all
the GUI-elements are displayed. private
void initialize_before_frame(String
parmstrLanguageCode) {/*
* Initialize
the structure with the set of parameters .
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . .
. System.exit(structJSBS_XML_DisplayStrings.StatusCode);
}/*
* Initialize
the XML-structure for the selectable Business Tasks. * The
variable for the structure is defined in the inherited class
JSBS_StartFrame). */ structJSBS_XML_Tasks
= new
JSBS_XML_Tasks(structJSBS_UniversalParameters);/* Verify
if the class was constructed without an error. */
if
(structJSBS_XML_Tasks.StatusCode
!=
JSBS_XML_Constants.CONST_OK)
{
System.out.println("Error
while building 'structJSBS_XML_Tasks'; StatusCode: "
+
(new
Integer(structJSBS_XML_Tasks.StatusCode)).toString());
System.exit(structJSBS_XML_Tasks.StatusCode);
}/* Display
the Task-List in the JTree designated to do this.
* This
works, even if the GUI-Element is not yet part of a frame and
displayed ;-). */
tree_SelectableTasks }
=
structJSBS_XML_Tasks.getTaskTree();To
verify, run the application and you should get a frame like that:
Reacting
to the button-click and open the Task-FrameThe
following step assumes, that the class inherites from class
JSBS_StartFrame.
Otherwise,
the Interface ActionListener
has to be implemented.
A
more detailed description with screenshots how to react to a
button-click and handle an action are in the documents JS_FC01i
– Create and code the class for the 'Task-Frame to maintain
'Projects' and Base
lesson 2, step 2: Adding an action: selecting the file with the
SQL-commands.
As
discussed in the documents above, it is wise to create an extra class
for handling actions. In
catchwords:
* Right
click onto the package (js_projassist.clientframes in our
example) and select >New>Class.* Enter
the Package (xxx_project_xxx.clientframes)
and
the
(Class-)Name (XXX_Project_XXX_CommandCenter__ActionHandler).
* Make sure that no checkbox is selected and click the
[ Finish ] button.
Copy
the code from JS_ProjAssist_CommandCenter__ActionHandler
into the just created class.
As there are no classes for
the Task-Frames are defined now, some error will show.
Please
comment out the lines with the 'construction' of the Task-Frame. *
-------------------------------
* Method to get the selected
code for the Business Task out of the entry-field
* and
call the frame with the chosen Business Task. */private
static void
openBusinessTask(JS_ProjAssist_CommandCenter parmCC){/* String
strInternalCode =
* Get
the internal code using a combined method that also fills the
parameter-fields.
* Instead of the parameter-fields,
'null'-values are passed to signal the method
* just to
return the internal code. */
parmCC.structJSBS_XML_Tasks.processParameterFields(parmCC.get_txt_Code(),
null,
null,
)null,
null, null,
null;/* Check
which button was clicked and call the appropriate method. */ if
(strInternalCode.equals("P"))
{// JS_ProjAssist_Project
frm_ JS_ProjAssist_Project
= new
JS_ProjAssist_Project(parmCC);// } frm_
JS_ProjAssist_Project.setVisible(true); }
That
the event can be handled, the following package has to be imported to
the class
JS_ProjAssist_CommandCenter:package
js_projassist.clientframes;
import
;java.awt.event.*import
js_base.frame.*;
import
js_base.structures.*;import
js_base.xml.*;
Finally,
a method actionPerformed(ActionEvent
e) must be defined in the class
JS_ProjAssist_CommandCenter.This
method is called when a button is clicked.
Its only function is
to call the method handleEvent()
in the just created class
and pass the parameter of class ActionEvent.JS_ProjAssist_CommandCenter__ActionHandler/*
*
-------------------------------
* Method that is triggered
when a button is clicked.
* This method overwrites the
method in the inherited class (JSBS_StartFrame). */ JS_ProjAssist_CommandCenter__ActionHandler.handleEvent(this,
e);public
void actionPerformed(ActionEvent e)
{
}
Loading
the parameters for database-access and writing the XML-structure with
the parameters
This
step is a prerequisite to access data on a database; i.e. to store
and retrieve data with a Task-Frame.
You
might bypass this step and create the Layout of the Task-Frame(s)
next.
But please do not forget this step – it is
a prerequisite to access a database after you implemented Business
Objects and Database-Access Objects.
A
more detailed description how to create and access a database is in
document Create the database-Table
'project' and establish the connection.
If
you are responsible for creating the database (and need a guideline),
please refer to Set up the
MySQLdatabase for access by JAVA-applications.
The
file with the xml-structure containing the parameters to access a
database or a Java Spplication Server (JAS) in the directory
'CONNECTIONS'.
For the theory of the directories containing
'parameters' please see the document Directory
Architecture.
A
more detailed description with an example is in the document
Structure of the
xml-file with the parameters for database- and JAS-connection
(Connections.xml in directory CONNECTIONS).
In
catchwords:
* Right
click onto the 'Project' and select >New>Folder.
* Enter
the Folder Name (CONNECTIONS)
(obey the case, please !) and
click the [ Finish ] button.
* Right
click onto the folder CONNECTIONS
Enter
the File Name (Connections.xml)
and click the [ Finish ] button.and
select >New>File.
*
* Copy the
xml-structure from here
into
the empty file.
First,
the library with the Connection-Managers (for database and Java
Application Server) has to be imported:
package
js_projassist.clientframes;
import
;java.awt.event.*import
js_base.connections.*;import
js_base.frame.*;
import
js_base.structures.*;import
js_base.xml.*;
Next,
the run-version of the application has to be set.
For an early
stage of development I strongly recommend to work with a local
database-system and not with a Java Application Server !
Storing
and retrieving from a local database-system makes it much easier to
use the debugger.
To set the run-version is the first command
after the class is constructed:/*
*
-------------------------------
* Method with code to be
executed before the GUI is build */
private
void initialize_before_frame(String
parmstrLanguageCode) {/*
* ********************
* Set the version of the application:
* >>
Please comment out the version you are not testing or which is not
for delivery ! << */
RunVersion
=
CONST_StandAlone;// RunVersion/*
=
CONST_FatClient;
* Initialize
the structure with the set of parameters
* (defined in
the inherited class JSBS_StartFrame).
*/
structJSBS_UniversalParameters
= new
JSBS_UniversalParameters(parmstrLanguageCode);
The
Class with the connection managers (for database or Java Application
Server) is constructed depending on the run-version.
The
construction of the structure includes the reading of the file
'Connections.xml', getting the parameters out of the XML-structure
and establishing the connection to the database or the Java
Application Server. private
void initialize_before_frame(String
parmstrLanguageCode) {.
. . . . . . . . . ..
. . . . . . . . . ..
. . . . . . . . . ./* Display
the Task-List in the JTree designated to do this.
* This
works, even if the GUI-Element is not yet part of a frame and
displayed ;-). */
tree_SelectableTasks
=
structJSBS_XML_Tasks.getTaskTree();/* Establish
the connection to the database-system and/or the JAS -
* depending
on the RunVersion. */
if
}((RunVersion
==
CONST_StandAlone)
|| (RunVersion
==
CONST_MobileClient))
{
structJSBS_DB_ConnectionManager
=
JSBS_DB_ConnectionManager(
new
structJSBS_UniversalParameters);/* Verify
if the class was constructed without an error. */
if
(structJSBS_DB_ConnectionManager.StatusCode
!=
JSBS_XML_Constants.CONST_OK)
{
System.out.println("Error
while building '+structJSBS_DB_ConnectionManager';
StatusCode: "
(new
Integer(structJSBS_DB_ConnectionManager.StatusCode)).toString()
+;
";
StatusMessage: " +
structJSBS_DB_ConnectionManager.StatusMsg)
System.exit(structJSBS_DB_ConnectionManager.StatusCode);
} }/*
*
-------------------------------
* Method with code to
construct and display the GUI (Graphic User Interface) */private
void initialize_frame() {
If
you want to run the application now, make shure that the
'Connections.xml' file with a valid XML-structure exists and the
database is established !If
the database is not already established and you need to continue
testing Task-Frames (without database access, of course !) you might
'comment out' the termination of the application after the
verification failed: /* Verify
if the class was constructed without an error. */
if
(structJSBS_DB_ConnectionManager.StatusCode
!=
JSBS_XML_Constants.CONST_OK)
{
System.out.println("Error
while building '+structJSBS_DB_ConnectionManager';
StatusCode: "
(new
Integer(structJSBS_DB_ConnectionManager.StatusCode)).toString();
+
";
StatusMessage: " +
structJSBS_DB_ConnectionManager.StatusMsg)/ System.exit(/structJSBS_DB_ConnectionManager.StatusCode);
}
dummy
for copyingRelated
Documents: