TopBlend: Here is the first difference. There are 79 differences. is old. is new.

javax.swing
Class DefaultButtonModel


java.lang.Object
  extended by javax.swing.DefaultButtonModel
All Implemented Interfaces:
ItemSelectable , Serializable , ButtonModel
Direct Known Subclasses:
JToggleButton.ToggleButtonModel

public class DefaultButtonModel
extends Object
implements ButtonModel, Serializable

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 JavaBeans TM has been added to the java.beans package. Please see XMLEncoder .


Field Summary
protected   String actionCommand
          The action command string fired by the button.            
static int ARMED
          Identifies the "armed" bit in the bitmask, which indicates           Indicates partial commitment towards choosing/triggering choosing 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           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           Indicates that the button has been "pressed" bit in (typically, when the bitmask, which indicates that the button mouse is pressed. released).
static int ROLLOVER
          Identifies the "rollover" bit in the bitmask, which indicates           Indicates that the mouse is over the button.
static int SELECTED
          Identifies the "selected" bit in the bitmask, which indicates           Indicates that the button has been selected.
protected  int stateMask
          The bitmask used to store the state of the button.            
 
Constructor Summary
DefaultButtonModel ()
          Constructs a DefaultButtonModel. default JButtonModel.
 
Method Summary
 void addActionListener ( ActionListener
          Adds an ActionListener to the model. button.
 void addChangeListener ( ChangeListener
          Adds a ChangeListener to the model. button.
 void addItemListener ( ItemListener
          Adds a listener an ItemListener to receive item events when the state of an item is changed by the user. button.
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 this 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 this button belongs to.
  ItemListener [] getItemListeners ()
          Returns an array of all the item listeners registered on this DefaultButtonModel.
<T extends EventListener >
T[]
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. this model
  Object [] getSelectedObjects ()
          Overridden to return null.
 boolean isArmed ()
          Indicates partial commitment towards triggering pressing the button.
 boolean isEnabled ()
          Indicates if whether the button can be selected or triggered pressed by an input device, such device (such as a mouse pointer. pointer).
 boolean isPressed ()
          Indicates if the whether button is has been 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. button.
 void removeChangeListener ( ChangeListener
          Removes a ChangeListener from the model. button.
 void removeItemListener ( ItemListener
          Removes an item listener. ItemListener from the button.
 void setActionCommand ( String
          Sets the action command actionCommand string that gets sent as part of the ActionEvent event when the button is triggered. pressed.
 void setArmed (boolean b)
          Marks the button as armed or unarmed. "armed".
 void setEnabled (boolean b)
          Enables or disables the button.
 void setGroup ( ButtonGroup
          Identifies the group the this 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 this 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

stateMask


protected int stateMask
The bitmask used to store the state of the button.


actionCommand


protected String actionCommand
The action command string fired by the button.


group


protected ButtonGroup group
The button group that the button belongs to.


mnemonic


protected int mnemonic
The button's mnemonic.


changeEvent


protected transient ChangeEvent changeEvent
Only one 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".


listenerList


protected EventListenerList listenerList
Stores the listeners on this model.


ARMED


public static final int ARMED
Identifies the "armed" bit in the bitmask, which indicates partial commitment towards choosing/triggering the button. Indicates partial commitment towards choosing the button.

See Also:
Constant Field Values

SELECTED


public static final int SELECTED
Identifies the "selected" bit in the bitmask, which indicates Indicates that the button has been selected. Only needed for certain types of buttons - such as radio button RadioButton or check box. Checkbox.

See Also:
Constant Field Values

PRESSED


public static final int PRESSED
Identifies the "pressed" bit in the bitmask, which indicates that the button is pressed. Indicates that the button has been "pressed" (typically, when the mouse is released).

See Also:
Constant Field Values

ENABLED


public static final int ENABLED
Identifies the "enabled" bit in the bitmask, which indicates Indicates that the button can be selected by an input device (such as a mouse pointer).

See Also:
Constant Field Values

ROLLOVER


public static final int ROLLOVER
Identifies the "rollover" bit in the bitmask, which indicates Indicates that the mouse is over the button.

See Also:
Constant Field Values
Constructor Detail

DefaultButtonModel


public DefaultButtonModel()
Constructs a DefaultButtonModel. default JButtonModel.

Method Detail

setActionCommand


public void setActionCommand(String actionCommand)
Description copied from interface: ButtonModel
Sets the action command actionCommand string that gets sent as part of the ActionEvent event when the button is triggered. pressed.

Specified by:
setActionCommand in interface ButtonModel
Parameters:
actionCommand - the String that identifies the generated event
See Also:
ButtonModel.getActionCommand() , ActionEvent.getActionCommand()

getActionCommand


public String getActionCommand()
Description copied from interface: ButtonModel
Returns the action command string for the button. Returns the action command for this button.

Specified by:
getActionCommand in interface ButtonModel
Returns:
the String that identifies the generated event
See Also:
ButtonModel.setActionCommand(java.lang.String) setActionCommand(java.lang.String)

isArmed


public boolean isArmed()
Description copied from interface: ButtonModel
Indicates partial commitment towards triggering pressing the button.

Specified by:
isArmed in interface ButtonModel
Returns:
true if the button is armed, and ready to be triggered pressed
See Also:
ButtonModel.setArmed(boolean) setArmed(boolean)

isSelected


public boolean isSelected()
Description copied from interface: ButtonModel
Indicates if the button has been selected. Only needed for certain types of buttons - such as radio buttons and check boxes. RadioButton or Checkbox.

Specified by:
isSelected in interface ButtonModel
Returns:
true if the button is selected

isEnabled


public boolean isEnabled()
Description copied from interface: ButtonModel
Indicates if the button can be selected or triggered by an input device, such as a mouse pointer. Indicates whether the button can be selected or pressed by an input device (such as a mouse pointer). (Checkbox-buttons are selected, regular buttons are "pressed".)

Specified by:
isEnabled in interface ButtonModel
Returns:
true if the button is enabled enabled, and therefore selectable (or pressable)

isPressed


public boolean isPressed()
Description copied from interface: ButtonModel
Indicates if the button is pressed. Indicates whether button has been pressed.

Specified by:
isPressed in interface ButtonModel
Returns:
true if the button is has been pressed

isRollover


public boolean isRollover()
Description copied from interface: ButtonModel
Indicates that the mouse is over the button.

Specified by:
isRollover in interface ButtonModel
Returns:
true if the mouse is over the button

setArmed


public void setArmed(boolean b)
Description copied from interface: ButtonModel
Marks the button as armed or unarmed. Marks the button as "armed". If the mouse button is released while it is over this item, the button's action event fires. If the mouse button is released elsewhere, the event does not fire and the button is disarmed.

Specified by:
setArmed in interface ButtonModel
Parameters:
b - whether or not the button should be armed b - true to arm the button so it can be selected

setEnabled


public void setEnabled(boolean b)
Description copied from interface: ButtonModel
Enables or disables the button.

Specified by:
setEnabled in interface ButtonModel
Parameters:
b - whether or not the button should be enabled b - true to enable the button
See Also:
ButtonModel.isEnabled() isEnabled()

setSelected


public void setSelected(boolean b)
Description copied from interface: ButtonModel
Selects or deselects the button.

Specified by:
setSelected in interface ButtonModel
Parameters:
b - true selects the button, false deselects the button

setPressed


public void setPressed(boolean b)
Description copied from interface: ButtonModel
Sets the button to pressed or unpressed.

Specified by:
setPressed in interface ButtonModel
Parameters:
b - whether or not the button should be pressed b - true to set the button to "pressed"
See Also:
ButtonModel.isPressed() isPressed()

setRollover


public void setRollover(boolean b)
Description copied from interface: ButtonModel
Sets or clears the button's rollover state

Specified by:
setRollover in interface ButtonModel
Parameters:
b - true to turn on rollover
See Also:
ButtonModel.isRollover() isRollover()

setMnemonic


public void setMnemonic(int key)
Description copied from interface: ButtonModel
Sets the keyboard mnemonic (shortcut key or accelerator key) for the this button.

Specified by:
setMnemonic in interface ButtonModel
Parameters:
key - an int specifying the accelerator key

getMnemonic


public int getMnemonic()
Description copied from interface: ButtonModel
Gets the keyboard mnemonic for the button. Gets the keyboard mnemonic for this model

Specified by:
getMnemonic in interface ButtonModel
Returns:
an int specifying the accelerator key
See Also:
ButtonModel.setMnemonic(int) setMnemonic(int)

addChangeListener


public void addChangeListener(ChangeListener l)
Description copied from interface: ButtonModel
Adds a ChangeListener to the model. Adds a ChangeListener to the button.

Specified by:
addChangeListener in interface ButtonModel
Parameters:
l - the listener to add

removeChangeListener


public void removeChangeListener(ChangeListener l)
Description copied from interface: ButtonModel
Removes a ChangeListener from the model. Removes a ChangeListener from the button.

Specified by:
removeChangeListener in interface ButtonModel
Parameters:
l - the listener to remove

getChangeListeners


public ChangeListener[] getChangeListeners()
Returns an array of all the change listeners registered on this DefaultButtonModel.

Returns:
all of this model's ChangeListeners or an empty array if no change listeners are currently registered
Since:
1.4
See Also:
addChangeListener(javax.swing.event.ChangeListener) , removeChangeListener(javax.swing.event.ChangeListener)

fireStateChanged


protected void fireStateChanged()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.

See Also:
EventListenerList

addActionListener


public void addActionListener(ActionListener l)
Description copied from interface: ButtonModel
Adds an ActionListener to the model. Adds an ActionListener to the button.

Specified by:
addActionListener in interface ButtonModel
Parameters:
l - the listener to add

removeActionListener


public void removeActionListener(ActionListener l)
Description copied from interface: ButtonModel
Removes an ActionListener from the model. Removes an ActionListener from the button.

Specified by:
removeActionListener in interface ButtonModel
Parameters:
l - the listener to remove

getActionListeners


public ActionListener[] getActionListeners()
Returns an array of all the action listeners registered on this DefaultButtonModel.

Returns:
all of this model's ActionListeners or an empty array if no action listeners are currently registered
Since:
1.4
See Also:
addActionListener(java.awt.event.ActionListener) , removeActionListener(java.awt.event.ActionListener)

fireActionPerformed


protected void fireActionPerformed(ActionEvent e)
Notifies all listeners that have registered interest for notification on this event type.

Parameters:
e - the ActionEvent to deliver to listeners
See Also:
EventListenerList

addItemListener


public void addItemListener(ItemListener l)
Description copied from interface: ItemSelectable
Adds a listener to receive item events when the state of an item is changed by the user. Item events are not sent when an item's state is set programmatically. If l is null, no exception is thrown and no action is performed. Adds an ItemListener to the button.

Specified by:
addItemListener in interface ItemSelectable
Specified by:
addItemListener in interface ButtonModel
Parameters:
l - the listener to receive events add
See Also:
ItemEvent

removeItemListener


public void removeItemListener(ItemListener l)
Description copied from interface: ItemSelectable
Removes an item listener. If l is null, no exception is thrown and no action is performed. Removes an ItemListener from the button.

Specified by:
removeItemListener in interface ItemSelectable
Specified by:
removeItemListener in interface ButtonModel
Parameters:
l - the listener being removed to remove
See Also:
ItemEvent

getItemListeners


public ItemListener[] getItemListeners()
Returns an array of all the item listeners registered on this DefaultButtonModel.

Returns:
all of this model's ItemListeners or an empty array if no item listeners are currently registered
Since:
1.4
See Also:
addItemListener(java.awt.event.ItemListener) , removeItemListener(java.awt.event.ItemListener)

fireItemStateChanged


protected void fireItemStateChanged(ItemEvent e)
Notifies all listeners that have registered interest for notification on this event type.

Parameters:
e - the ItemEvent to deliver to listeners
See Also:
EventListenerList

getListeners


public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns an array of all the objects currently registered as 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.

Parameters:
listenerType - the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
Returns:
an array of all objects registered as FooListeners on this model, or an empty array if no such listeners have been added
Throws:
ClassCastException - if listenerType doesn't specify a class or interface that implements java.util.EventListener
Since:
1.3
See Also:
getActionListeners() , getChangeListeners() , getItemListeners()

getSelectedObjects


public Object[] getSelectedObjects()
Overridden to return null.

Specified by:
getSelectedObjects in interface ItemSelectable

setGroup


public void setGroup(ButtonGroup group)
Description copied from interface: ButtonModel
Identifies the group the this button belongs to -- needed for radio buttons, which are mutually exclusive within their group.

Specified by:
setGroup in interface ButtonModel
Parameters:
group - the ButtonGroup the this button belongs to

getGroup


public ButtonGroup getGroup()
Returns the group that the this button belongs to. Normally used with radio buttons, which are mutually exclusive within their group.

Returns:
the a ButtonGroup that the this button belongs to
Since:
1.3