| 
 | Java™ Platform Standard Ed. 6 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.DefaultButtonModel
public class DefaultButtonModel
The default implementation of a 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 JavaBeansTM
 has been added to the java.beans package.
 Please see XMLEncoder.
| Field Summary | |
|---|---|
| protected  String | actionCommandThe action command string fired by the button. | 
| static int | ARMEDIdentifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button. | 
| protected  ChangeEvent | changeEventOnly one ChangeEventis needed per button model
 instance since the event's only state is the source property. | 
| static int | ENABLEDIdentifies 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 | groupThe button group that the button belongs to. | 
| protected  EventListenerList | listenerListStores the listeners on this model. | 
| protected  int | mnemonicThe button's mnemonic. | 
| static int | PRESSEDIdentifies the "pressed" bit in the bitmask, which indicates that the button is pressed. | 
| static int | ROLLOVERIdentifies the "rollover" bit in the bitmask, which indicates that the mouse is over the button. | 
| static int | SELECTEDIdentifies the "selected" bit in the bitmask, which indicates that the button has been selected. | 
| protected  int | stateMaskThe bitmask used to store the state of the button. | 
| Constructor Summary | |
|---|---|
| DefaultButtonModel()Constructs a DefaultButtonModel. | |
| Method Summary | ||
|---|---|---|
|  void | addActionListener(ActionListener l)Adds an ActionListenerto the model. | |
|  void | addChangeListener(ChangeListener l)Adds a ChangeListenerto the model. | |
|  void | addItemListener(ItemListener l)Adds an ItemListenerto the model. | |
| protected  void | fireActionPerformed(ActionEvent e)Notifies all listeners that have registered interest for notification on this event type. | |
| protected  void | fireItemStateChanged(ItemEvent e)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. | |
| 
 | getListeners(Class<T> listenerType)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 l)Removes an ActionListenerfrom the model. | |
|  void | removeChangeListener(ChangeListener l)Removes a ChangeListenerfrom the model. | |
|  void | removeItemListener(ItemListener l)Removes an ItemListenerfrom the model. | |
|  void | setActionCommand(String actionCommand)Sets the action command string that gets sent as part of the ActionEventwhen 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 group)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. | |
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
protected int stateMask
protected String actionCommand
protected ButtonGroup group
protected int mnemonic
protected transient ChangeEvent changeEvent
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 EventListenerList listenerList
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
| Constructor Detail | 
|---|
public DefaultButtonModel()
DefaultButtonModel.
| Method Detail | 
|---|
public void setActionCommand(String actionCommand)
ActionEvent when the button is triggered.
setActionCommand in interface ButtonModelactionCommand - the String that identifies the generated eventButtonModel.getActionCommand(), 
ActionEvent.getActionCommand()public String getActionCommand()
getActionCommand in interface ButtonModelString that identifies the generated eventButtonModel.setActionCommand(java.lang.String)public boolean isArmed()
isArmed in interface ButtonModeltrue if the button is armed,
         and ready to be triggeredButtonModel.setArmed(boolean)public boolean isSelected()
isSelected in interface ButtonModeltrue if the button is selectedpublic boolean isEnabled()
isEnabled in interface ButtonModeltrue if the button is enabledpublic boolean isPressed()
isPressed in interface ButtonModeltrue if the button is pressedpublic boolean isRollover()
isRollover in interface ButtonModeltrue if the mouse is over the buttonpublic void setArmed(boolean b)
setArmed in interface ButtonModelb - whether or not the button should be armedpublic void setEnabled(boolean b)
setEnabled in interface ButtonModelb - whether or not the button should be enabledButtonModel.isEnabled()public void setSelected(boolean b)
setSelected in interface ButtonModelb - true selects the button,
          false deselects the buttonpublic void setPressed(boolean b)
setPressed in interface ButtonModelb - whether or not the button should be pressedButtonModel.isPressed()public void setRollover(boolean b)
setRollover in interface ButtonModelb - whether or not the button is in the rollover stateButtonModel.isRollover()public void setMnemonic(int key)
setMnemonic in interface ButtonModelkey - an int specifying the accelerator keypublic int getMnemonic()
getMnemonic in interface ButtonModelButtonModel.setMnemonic(int)public void addChangeListener(ChangeListener l)
ChangeListener to the model.
addChangeListener in interface ButtonModell - the listener to addpublic void removeChangeListener(ChangeListener l)
ChangeListener from the model.
removeChangeListener in interface ButtonModell - the listener to removepublic ChangeListener[] getChangeListeners()
DefaultButtonModel.
ChangeListeners 
         or an empty
         array if no change listeners are currently registeredaddChangeListener(javax.swing.event.ChangeListener), 
removeChangeListener(javax.swing.event.ChangeListener)protected void fireStateChanged()
EventListenerListpublic void addActionListener(ActionListener l)
ActionListener to the model.
addActionListener in interface ButtonModell - the listener to addpublic void removeActionListener(ActionListener l)
ActionListener from the model.
removeActionListener in interface ButtonModell - the listener to removepublic ActionListener[] getActionListeners()
DefaultButtonModel.
ActionListeners 
         or an empty
         array if no action listeners are currently registeredaddActionListener(java.awt.event.ActionListener), 
removeActionListener(java.awt.event.ActionListener)protected void fireActionPerformed(ActionEvent e)
e - the ActionEvent to deliver to listenersEventListenerListpublic void addItemListener(ItemListener l)
ItemListener to the model.
addItemListener in interface ItemSelectableaddItemListener in interface ButtonModell - the listener to addItemEventpublic void removeItemListener(ItemListener l)
ItemListener from the model.
removeItemListener in interface ItemSelectableremoveItemListener in interface ButtonModell - the listener to removeItemEventpublic ItemListener[] getItemListeners()
DefaultButtonModel.
ItemListeners 
         or an empty
         array if no item listeners are currently registeredaddItemListener(java.awt.event.ItemListener), 
removeItemListener(java.awt.event.ItemListener)protected void fireItemStateChanged(ItemEvent e)
e - the ItemEvent to deliver to listenersEventListenerListpublic <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.EventListenergetActionListeners(), 
getChangeListeners(), 
getItemListeners()public Object[] getSelectedObjects()
null.
getSelectedObjects in interface ItemSelectablepublic void setGroup(ButtonGroup group)
setGroup in interface ButtonModelgroup - the ButtonGroup the button belongs topublic ButtonGroup getGroup()
ButtonGroup that the button belongs to| 
 | Java™ Platform Standard Ed. 6 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
Copyright © 1993, 2010, Oracle and/or its affiliates. All rights reserved.