| ButtonGroup |
|
typedict |
| |
A
ButtonGroup
is the interface to the Java Swing ButtonGroup object.
It functions to provide multiple-exclusion functionality to a set of buttons.
Button objects are added to a button group by assigning the
button group object to the
group
field of the button object, which is either a
JButton
or a
JMenuItem.
Yoix programs normally interact with a
ButtonGroup
by reading or writing the following fields:
| items |
A read-only field containing an
Array
of items currently managed by the button group object.
| | model |
An
int
that should be
1
(the default) or
0
(AWT compatibility mode)
that determines what happens when the
selected
field is read.
Setting
model
to
0,
tells
selected
that it should return a
String
that is the action command associated with the currently selected
member of the button group.
The
model
field was introduced to help with AWT conversions and usually is only set to
0
indirectly when the
JCheckboxGroup
or
JCheckBoxGroup
types are used.
| | selected |
An
Object
that identifies the member of the button group that is currently selected.
Reading
selected
when
model
is
1
(the default)
returns the object in the button group that is selected or
NULL
if no object is selected.
Reading
selected
when
model
is
0
(AWT compatibility mode) returns the action command, as a
String,
that is associated with the object in the button group that is selected.
Writing a
String
that matches one of the action command strings associated with the items in the button group
immediately selects that matching item.
Alternatively, writing an object that is one of the items in the button group
immediately selects that item.
In either case, writing a
NULL
clears the current selection within the group meaning none of the items are selected.
| | size |
A read-only field containing an
int
that gives a count of the objects currently managed by the button group.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
| |
| Example: |
The program,
import yoix.*.*;
ButtonGroup bg;
JFrame f = {
FlowLayout layoutmanager = {
int hgap = 10;
int vgap = 72;
};
Color background = Color.gray;
Array layout = {
new JButton {
ButtonGroup group = bg;
String text = "Red";
int type = RADIO_BUTTON;
actionPerformed(e) {
root.background = Color.red;
}
},
new JButton {
ButtonGroup group = bg;
String text = "Blue";
int type = RADIO_BUTTON;
actionPerformed(e) {
root.background = Color.blue;
}
},
new JButton {
ButtonGroup group = bg;
String text = "Green";
int type = RADIO_BUTTON;
actionPerformed(e) {
root.background = Color.green;
}
},
new JButton {
String text = "Clear";
actionPerformed(e) {
bg.selected = null;
root.background = Color.gray;
}
},
new JButton {
String text = "Quit";
actionPerformed(e) {
exit(0);
}
},
};
};
f.visible = TRUE;
uses three radio buttons to set the background color of the components to
red, green or blue.
A "Clear" button uses the button group to clear the selected radio button and
then resets the background color.
A "Quit" button is also included.
| | |
| See Also: |
JButton,
JCheckBox,
JCheckBoxGroup,
JCheckBoxMenuItem,
JMenuItem,
JRadioButton,
JRadioButtonMenuItem,
JToggleButton
|
|
Yoix is a registered trademark of AT&T Intellectual Property.
|