Java Reference
In-Depth Information
valuable business logic, you need to integrate the
GUI
with back-end services.
Let's run through a quick overview of the typical process used to add functionality
to a
GUI
form in
IDEA
:
Bind the form to a Java class, and bind its important components to fields of that
class.
The
GUI
Designer depends on the fact that a Java class will under-
pin the form. You can bind the form to an existing class or create one on
the fly; similarly, you can bind components to existing fields or create
new ones as needed.
1
Add a constructor to the form class.
If any fields in the form should be initial-
ized, you can create a constructor in the Java class. You can use
IDEA
's
Code | Generate
command or press
Alt+Insert
to create this constructor.
2
If necessary, define functional groups of components.
Some components (like
radio buttons) are logically divided into groups. These group relation-
ships need to be implemented in the constructor of the underlying
Java class.
3
Implement actions for all components that perform actions, such as
JB
uttons.
The
business logic that is called by interactions with the
GUI
must be con-
nected by hand using the Swing event model.
4
If desired, bind component fields to data from a JavaBean.
The
GUI
Designer
has the ability to leverage the JavaBean framework and populate the
GUI
's state from bean data. If you're working with JavaBeans, you may
wish to configure the
GUI
in this fashion.
5
Implement initialization code that uses the form.
Provide a point of entry
where the form can be run and tested.
6
10.5.1
Binding forms and their components
Once you're happy with your user interface's layout and behavior, you need to
bind it to a class in order to use it as part of your application. After associating
your form with its class, you then bind each of the components you wish to access
programmatically to the field variables of your form class.
Binding the form to a class
To be useful, your form must be bound to a class that contains the methods and
behavior that do whatever the form has been designed for. You can bind a form to
any class: The class serves as a container for accessing the form and its components.
In the
GUI
Designer, select the
Form
root node from the component tree, and
enter the fully qualified name of the class to which you wish to bind your form in