Java Reference
In-Depth Information
JDialog we only need the constructor and some methods to add components.
The semantics of the methods is the same as that for JFrames .
JDialog(Frame parent, String title, boolean modal)
getContentPane.add(Component comp)
setVisible( boolean b)
pack()
In order to have a proper display we call the default constructor of JDialog in the
constructor of SearchDialog using the super -method.
12.4
Radio buttons
The two buttons 'Find' and 'Cancel' are JButtons ,asin TextAnalysisGUI in
Chapter 4. The buttons 'Yes' and 'No' are radio button s. Only one of them can
be pressed at a time. These buttons are implemented using the class JRadioBut-
ton .Aradio button is rectangular. It contains a circular area on the left and a
label to the right of it. Radio buttons can be pressed and they can be grouped .
They stay pressed until another radio button of the group is pressed. A black dot
appears inside the circular area if the button is pressed. We need the following
methods:
JRadioButton(String buttonName)
setSelected( boolean pressed)
setActionCommand(String command)
String getActionCommand()
JRadioButton(String buttonName) creates a button labelled buttonName .
setSelected(boolean pressed) determines whether the button is selected
( pressed = true )ornot ( pressed = false ). In the first case the black dot
is visible inside the circular area of the button. This method is used initially to
set which buttons are pressed before the first user action.
setActionCommand(String command) assigns the string command as the action
command to the button. Radio buttons are not automatically assigned an action
command. This is because their label is often not a text but a picture. We set
the action command ourselves using method setActionCommand .
getActionCommand() returns the action command assigned to the button.
We still have to make sure that only one button is pressed at a time. This is done
by grouping the buttons. We use the class ButtonGroup from the AWT library.
Below we list the constructor and some methods:
JButtonGroup();
add(JRadioButton button)
String getSelection().getActionCommand()
Search WWH ::




Custom Search