java.awt

Class Button

public class Button extends Component implements Serializable, Accessible

This class provides a button widget for the AWT.
Nested Class Summary
protected classButton.AccessibleAWTButton
Constructor Summary
Button()
Initializes a new instance of Button with no label.
Button(String label)
Initializes a new instance of Button with the specified label.
Method Summary
voidaddActionListener(ActionListener listener)
Adds a new entry to the list of listeners that will receive action events from this button.
voidaddNotify()
Notifies this button that it should create its native peer object.
AccessibleContextgetAccessibleContext()
Gets the AccessibleContext associated with this Button.
StringgetActionCommand()
Returns the action command name for this button.
ActionListener[]getActionListeners()
Returns all added ActionListener objects.
StringgetLabel()
Returns the label for this button.
<T extends EventListener> T[]getListeners(Class<T> listenerType)
Returns all registered EventListers of the given listenerType. listenerType must be a subclass of EventListener, or a ClassClassException is thrown.
protected StringparamString()
Returns a debugging string for this button.
protected voidprocessActionEvent(ActionEvent event)
This method dispatches an action event for this button to any registered listeners.
protected voidprocessEvent(AWTEvent event)
Processes an event for this button.
voidremoveActionListener(ActionListener listener)
Removes the specified listener from the list of listeners that will receive action events from this button.
voidsetActionCommand(String actionCommand)
Sets the action command name for this button to the specified value.
voidsetLabel(String label)
Sets the label for this button to the specified value.

Constructor Detail

Button

public Button()
Initializes a new instance of Button with no label.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() returns true

Button

public Button(String label)
Initializes a new instance of Button with the specified label. The action command name is also initialized to this value.

Parameters: label The label to display on the button.

Throws: HeadlessException If GraphicsEnvironment.isHeadless() returns true

Method Detail

addActionListener

public void addActionListener(ActionListener listener)
Adds a new entry to the list of listeners that will receive action events from this button.

Parameters: listener The listener to add.

addNotify

public void addNotify()
Notifies this button that it should create its native peer object.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Button. The context is created, if necessary.

Returns: the associated context

getActionCommand

public String getActionCommand()
Returns the action command name for this button.

Returns: The action command name for this button.

getActionListeners

public ActionListener[] getActionListeners()
Returns all added ActionListener objects.

Returns: an array of listeners

Since: 1.4

getLabel

public String getLabel()
Returns the label for this button.

Returns: The label for this button.

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns all registered EventListers of the given listenerType. listenerType must be a subclass of EventListener, or a ClassClassException is thrown.

Parameters: listenerType the listener type to return

Returns: an array of listeners

Throws: ClassCastException If listenerType doesn't specify a class or interface that implements @see java.util.EventListener.

Since: 1.3

paramString

protected String paramString()
Returns a debugging string for this button.

Returns: A debugging string for this button.

processActionEvent

protected void processActionEvent(ActionEvent event)
This method dispatches an action event for this button to any registered listeners.

Parameters: event The event to process.

processEvent

protected void processEvent(AWTEvent event)
Processes an event for this button. If the specified event is an instance of ActionEvent, then the processActionEvent() method is called to dispatch it to any registered listeners. Otherwise, the superclass method will be invoked. Note that this method will not be called at all unless ActionEvent's are enabled. This will be done implicitly if any listeners are added.

Parameters: event The event to process.

removeActionListener

public void removeActionListener(ActionListener listener)
Removes the specified listener from the list of listeners that will receive action events from this button.

Parameters: listener The listener to remove.

setActionCommand

public void setActionCommand(String actionCommand)
Sets the action command name for this button to the specified value.

Parameters: actionCommand The new action command name.

setLabel

public void setLabel(String label)
Sets the label for this button to the specified value.

Parameters: label The new label for this button.