public class DefaultButtonModel extends Objectimplements ButtonModel , Serializable
Button component's data model.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.
| Modifier and Type | Field and Description |
|---|---|
protected String |
actionCommand
The action command string fired by the button.
|
static int |
ARMED
Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button.
|
protected ChangeEvent |
changeEvent
Only one
ChangeEvent is needed per button model instance since the event's only state is the source property.
|
static int |
ENABLED
Identifies the "enabled" bit in the bitmask, which indicates that the button can be selected by an input device (such as a mouse pointer).
|
protected ButtonGroup |
group
The button group that the button belongs to.
|
protected EventListenerList |
listenerList
Stores the listeners on this model.
|
protected int |
mnemonic
The button's mnemonic.
|
static int |
PRESSED
Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed.
|
static int |
ROLLOVER
Identifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button.
|
static int |
SELECTED
Identifies the "selected" bit in the bitmask, which indicates that the button has been selected.
|
protected int |
stateMask
The bitmask used to store the state of the button.
|
| Constructor and Description |
|---|
DefaultButtonModel()
Constructs a
DefaultButtonModel.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addActionListener(ActionListener
Adds an
ActionListener to the model.
|
void |
addChangeListener(ChangeListener
Adds a
ChangeListener to the model.
|
void |
addItemListener(ItemListener
Adds an
ItemListener to the model.
|
protected void |
fireActionPerformed(ActionEvent
Notifies all listeners that have registered interest for notification on this event type.
|
protected void |
fireItemStateChanged(ItemEvent
Notifies all listeners that have registered interest for notification on this event type.
|
protected void |
fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type.
|
String |
getActionCommand()
Returns the action command string for the button.
|
ActionListener |
getActionListeners()
Returns an array of all the action listeners registered on this
DefaultButtonModel.
|
ChangeListener |
getChangeListeners()
Returns an array of all the change listeners registered on this
DefaultButtonModel.
|
ButtonGroup |
getGroup()
Returns the group that the button belongs to.
|
ItemListener |
getItemListeners()
Returns an array of all the item listeners registered on this
DefaultButtonModel.
|
<T extends EventListener |
getListeners(Class
Returns an array of all the objects currently registered as
FooListeners upon this model.
|
int |
getMnemonic()
Gets the keyboard mnemonic for the button.
|
Object |
getSelectedObjects()
Overridden to return
null.
|
boolean |
isArmed()
Indicates partial commitment towards triggering the button.
|
boolean |
isEnabled()
Indicates if the button can be selected or triggered by an input device, such as a mouse pointer.
|
boolean |
isPressed()
Indicates if the button is pressed.
|
boolean |
isRollover()
Indicates that the mouse is over the button.
|
boolean |
isSelected()
Indicates if the button has been selected.
|
void |
removeActionListener(ActionListener
Removes an
ActionListener from the model.
|
void |
removeChangeListener(ChangeListener
Removes a
ChangeListener from the model.
|
void |
removeItemListener(ItemListener
Removes an
ItemListener from the model.
|
void |
setActionCommand(String
Sets the action command string that gets sent as part of the
ActionEvent when the button is triggered.
|
void |
setArmed(boolean b)
Marks the button as armed or unarmed.
|
void |
setEnabled(boolean b)
Enables or disables the button.
|
void |
setGroup(ButtonGroup
Identifies the group the button belongs to -- needed for radio buttons, which are mutually exclusive within their group.
|
void |
setMnemonic(int key)
Sets the keyboard mnemonic (shortcut key or accelerator key) for the button.
|
void |
setPressed(boolean b)
Sets the button to pressed or unpressed.
|
void |
setRollover(boolean b)
Sets or clears the button's rollover state
|
void |
setSelected(boolean b)
Selects or deselects the button.
|
protected int stateMask
protected StringactionCommand
protected ButtonGroupgroup
protected int mnemonic
protected transient ChangeEventchangeEvent
ChangeEvent is needed per button model instance since the event's only state is the source property. The source of events generated is always "this".
protected EventListenerListlistenerList
public static final int ARMED
public static final int SELECTED
public static final int PRESSED
public static final int ENABLED
public static final int ROLLOVER
public void setActionCommand(StringactionCommand)
ActionEvent when the button is triggered.
setActionCommand in interface
ButtonModel
actionCommand - the
String that identifies the generated event
ButtonModel.getActionCommand() ,
ActionEvent.getActionCommand()
public StringgetActionCommand()
getActionCommand in interface
ButtonModel
String that identifies the generated event
ButtonModel.setActionCommand(java.lang.String)
public boolean isArmed()
isArmed in interface
ButtonModel
true if the button is armed, and ready to be triggered
ButtonModel.setArmed(boolean)
public boolean isSelected()
isSelected in interface
ButtonModel
true if the button is selected
public boolean isEnabled()
isEnabled in interface
ButtonModel
true if the button is enabled
public boolean isPressed()
isPressed in interface
ButtonModel
true if the button is pressed
public boolean isRollover()
isRollover in interface
ButtonModel
true if the mouse is over the button
public void setArmed(boolean b)
setArmed in interface
ButtonModel
b - whether or not the button should be armed
public void setEnabled(boolean b)
setEnabled in interface
ButtonModel
b - whether or not the button should be enabled
ButtonModel.isEnabled()
public void setSelected(boolean b)
setSelected in interface
ButtonModel
b -
true selects the button,
false deselects the button
public void setPressed(boolean b)
setPressed in interface
ButtonModel
b - whether or not the button should be pressed
ButtonModel.isPressed()
public void setRollover(boolean b)
setRollover in interface
ButtonModel
b - whether or not the button is in the rollover state
ButtonModel.isRollover()
public void setMnemonic(int key)
setMnemonic in interface
ButtonModel
key - an int specifying the accelerator key
public int getMnemonic()
getMnemonic in interface
ButtonModel
ButtonModel.setMnemonic(int)
public void addChangeListener(ChangeListenerl)
ChangeListener to the model.
addChangeListener in interface
ButtonModel
l - the listener to add
public void removeChangeListener(ChangeListenerl)
ChangeListener from the model.
removeChangeListener in interface
ButtonModel
l - the listener to remove
public ChangeListener[] getChangeListeners()
DefaultButtonModel.
ChangeListeners or an empty array if no change listeners are currently registered
addChangeListener(javax.swing.event.ChangeListener),
removeChangeListener(javax.swing.event.ChangeListener)
protected void fireStateChanged()
EventListenerList
public void addActionListener(ActionListenerl)
ActionListener to the model.
addActionListener in interface
ButtonModel
l - the listener to add
public void removeActionListener(ActionListenerl)
ActionListener from the model.
removeActionListener in interface
ButtonModel
l - the listener to remove
public ActionListener[] getActionListeners()
DefaultButtonModel.
ActionListeners or an empty array if no action listeners are currently registered
addActionListener(java.awt.event.ActionListener),
removeActionListener(java.awt.event.ActionListener)
protected void fireActionPerformed(ActionEvente)
e - the
ActionEvent to deliver to listeners
EventListenerList
public void addItemListener(ItemListenerl)
ItemListener to the model.
addItemListener in interface
ItemSelectable
addItemListener in interface
ButtonModel
l - the listener to add
ItemEvent
public void removeItemListener(ItemListenerl)
ItemListener from the model.
removeItemListener in interface
ItemSelectable
removeItemListener in interface
ButtonModel
l - the listener to remove
ItemEvent
public ItemListener[] getItemListeners()
DefaultButtonModel.
ItemListeners or an empty array if no item listeners are currently registered
addItemListener(java.awt.event.ItemListener),
removeItemListener(java.awt.event.ItemListener)
protected void fireItemStateChanged(ItemEvente)
e - the
ItemEvent to deliver to listeners
EventListenerList
public <T extends EventListener> T[] getListeners(Class <T> listenerType)
FooListeners upon this model.
FooListeners are registered using the
addFooListener method.
You can specify the listenerType argument with a class literal, such as FooListener.class. For example, you can query a DefaultButtonModel instance m for its action listeners with the following code:
ActionListener[] als = (ActionListener[])(m.getListeners(ActionListener.class));If no such listeners exist, this method returns an empty array.
listenerType - the type of listeners requested; this parameter should specify an interface that descends from
java.util.EventListener
FooListeners on this model, or an empty array if no such listeners have been added
ClassCastException - if
listenerType doesn't specify a class or interface that implements
java.util.EventListener
getActionListeners(),
getChangeListeners(),
getItemListeners()
public Object[] getSelectedObjects()
null.
public void setGroup(ButtonGroupgroup)
setGroup in interface
ButtonModel
group - the
ButtonGroup the button belongs to
public ButtonGroupgetGroup()
ButtonGroup that the button belongs to