Java Reference
In-Depth Information
JButtonGroup() constructs a button group not yet containing any button.
add(JRadioButton button) adds the radio button button to the group.
getSelection().getActionCommand() returns the action command of the but-
ton which is currently selected in the group. This statement combines methods
from ButtonGroup and ButtonModel ,aclass we do not discuss here.
Once the buttons are in a group, only one at a time can be pressed. Pressing
an unpressed one releases the one previously pressed. The listing of the whole
dialogue can be found in Section 12.5.2.
12.5
Exchange of information between dialogue
and program
Now that the layout of the dialogue is completed we take care of the information
exchange. We begin by describing the general principle and then apply it to our
editor.
12.5.1
General scheme for information transfer
Depending on how much information has to be exchanged between a dialogue
and the program that created it, different methods of information exchange can be
used. Return values may be used to transfer a single variable from the dialogue back
to the program. This is, for example, done by JFileChooser . Further information
can then be accessed using get -methods of the dialogue such as getSelectedFile
and JFileChooser . This approach is appropriate if the data format is fixed and
not too much data have to be transferred.
A more flexible way of realizing information transfer is to define a special object
for this purpose. The data transfer object has to be defined by the programmer to
store all the information to be transferred between the program and the dialogue.
It should also have get and set methods to access the data; see also Section B.3.
A data transfer object can be used to transfer data both ways, from the pro-
gram to the dialogue and back. It might contain some initial information which is
displayed by the dialogue. This is then altered by the user in the dialogue and the
modified data are returned to the program. We describe the framework for this
approach below and incorporate it into our editor after that. The basic steps for a
data transfer using an object are:
1. Define a class for the data transfer object . Let us call it DataTransferObject
here. A DataTransferObject contains the information that is to be exchanged
between the dialogue and the application that created the dialogue. Define the
get and set methods to access the data.
2. Define a dialogue class, say MyDialog , with the desired layout. The dialogue
should also contain two buttons labelled, for example, 'OK' and 'Cancel'.
Search WWH ::




Custom Search