public class ButtonGroup extends Observable
ButtonGroup
object means that
turning "on" one of those buttons turns off all other buttons in the group.
The main difference between this group and the swing one is that you can deselected buttons by clicking on them
and have a group without no selected button (see setAutoDeselect(boolean)
).
Another difference is that this class extends the java.util.Observable class and calls its observers update method
when the selected button changes.
Constructor and Description |
---|
ButtonGroup()
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(AbstractButton b)
Adds a button to this group.
|
void |
clearSelection()
Clears the selection such that none of the buttons in the
ButtonGroup are selected. |
AbstractButton |
getSelected()
Returns the selected button.
|
void |
remove(AbstractButton b)
Removes a button from this group.
|
void |
setAutoDeselect(boolean autoDeselect)
Activates/deactivates the ability to deselect a selected button by cliking onto it.
|
void |
setSelected(AbstractButton b)
Changes the selected button.
|
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
public void add(AbstractButton b)
b
- the button to be addedNullPointerException
- if the button is nullpublic void remove(AbstractButton b)
b
- the button to be removedIllegalArgumentException
- if the button is unknown in this groupNullPointerException
- if the button is nullpublic void clearSelection()
ButtonGroup
are selected.public AbstractButton getSelected()
public void setSelected(AbstractButton b)
b
- the button to be selected (null deselects all buttons)IllegalArgumentException
- if the button is not in this grouppublic void setAutoDeselect(boolean autoDeselect)
autoDeselect
- true to have selected button to be deactivated when clickedCopyright © 2022. All rights reserved.