Quit
" button as it appears
under the Solaris operating system:
The first view shows the button as it appears normally. The second view shows the button when it has input focus. Its outline is darkened to let the user know that it is an active object. The third view shows the button when the user clicks the mouse over the button, and thus requests that an action be performed.
The gesture of clicking on a button with the mouse
is associated with one instance of ActionEvent
,
which is sent out when the mouse is both pressed and released
over the button. If an application is interested in knowing
when the button has been pressed but not released, as a separate
gesture, it can specialize processMouseEvent
,
or it can register itself as a listener for mouse events by
calling addMouseListener
. Both of these methods are
defined by Component
, the abstract superclass of
all components.
When a button is pressed and released, AWT sends an instance
of ActionEvent
to the button, by calling
processEvent
on the button. The button's
processEvent
method receives all events
for the button; it passes an action event along by
calling its own processActionEvent
method.
The latter method passes the action event on to any action
listeners that have registered an interest in action
events generated by this button.
If an application wants to perform some action based on
a button being pressed and released, it should implement
ActionListener
and register the new listener
to receive events from this button, by calling the button's
addActionListener
method. The application can
make use of the button's action command as a messaging protocol.
java.awt.event.ActionEvent
, java.awt.event.ActionListener
, java.awt.Component#processMouseEvent
, java.awt.Component#addMouseListener
Modifier and Type | Class and Description |
---|---|
protected class | Button.
This class implements accessibility support for the
|
Modifier and Type | Field and Description |
---|---|
pack-priv String | actionCommand
The action to be performed once a button has been pressed. |
pack-priv transient ActionListener | |
private static final String | |
private int | buttonSerializedDataVersion
Serialized data version. |
pack-priv String | label
The button's label. |
private static int | |
private static final long | serialVersionUID
Use serialVersionUID from JDK 1.1 for interoperability.
|
Access | Constructor and Description |
---|---|
public | |
public |
Modifier and Type | Method and Description |
---|---|
public synchronized void | addActionListener(ActionListener
the action listener l)Adds the specified action listener to receive action events from this button. |
public void | |
pack-priv String | constructComponentName()
Overrides java. |
pack-priv boolean | |
public AccessibleContext | Returns: anAccessibleAWTButton that serves as the
AccessibleContext of this Button Overrides java. Implements javax. AccessibleContext associated with
this Button .
|
public String | Returns: the action command name (or label) for this buttonReturns the command name of the action event fired by this button. |
public synchronized ActionListener[] | Returns: all of this button'sActionListener s
or an empty array if no action
listeners are currently registeredReturns an array of all the action listeners registered on this button. |
public String | Returns: the button's label, ornull
if the button has no label.Gets the label of this button. |
public <T extends EventListener> T[] | Returns: an array of all objects registered asFooListener s on this button,
or an empty array if no such
listeners have been addedthe type of listeners requested; this parameter
should specify an interface that descends from
listenerType)java.util.EventListener Overrides java. FooListener s
upon this Button .
|
protected String | Returns: the parameter string of this buttonOverrides java. Button .
|
protected void | processActionEvent(ActionEvent
the action event e)Processes action events occurring on this button
by dispatching them to any registered
|
protected void | processEvent(AWTEvent
the event e)Overrides java. |
private void | readObject(ObjectInputStream
the s)ObjectInputStream to readHides java. ObjectInputStream and if
it isn't null adds a listener to
receive action events fired by the button.
|
public synchronized void | removeActionListener(ActionListener
the action listener l)Removes the specified action listener so that it no longer receives action events from this button. |
public void | setActionCommand(String
a string used to set the button's
action command.
If the string is command)null then the action command
is set to match the label of the button.Sets the command name for the action event fired by this button. |
public void | |
private void | writeObject(ObjectOutputStream
the s)
Writes default serializable fields to stream.
ObjectOutputStream to write |
actionCommand | back to summary |
---|---|
pack-priv String actionCommand The action to be performed once a button has been pressed. This value may be null.
|
actionListener | back to summary |
---|---|
pack-priv transient ActionListener actionListener |
base | back to summary |
---|---|
private static final String base |
buttonSerializedDataVersion | back to summary |
---|---|
private int buttonSerializedDataVersion Serialized data version. |
label | back to summary |
---|---|
pack-priv String label The button's label. This value may be null.
|
nameCounter | back to summary |
---|---|
private static int nameCounter |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.1 for interoperability. |
Button | back to summary |
---|---|
public Button() throws HeadlessException Constructs a button with an empty string for its label.
|
Button | back to summary |
---|---|
public Button(String label) throws HeadlessException Constructs a button with the specified label.
|
addActionListener | back to summary |
---|---|
public synchronized void addActionListener(ActionListener l) Adds the specified action listener to receive action events from this button. Action events occur when a user presses or releases the mouse over this button. If l is null, no exception is thrown and no action is performed. Refer to AWT Threading Issues for details on AWT's threading model.
|
addNotify | back to summary |
---|---|
public void addNotify() Overrides java. Creates the peer of the button. The button's peer allows the application to change the look of the button without changing its functionality.
|
constructComponentName | back to summary |
---|---|
pack-priv String constructComponentName() Overrides java. Construct a name for this component. Called by getName() when the name is null. |
eventEnabled | back to summary |
---|---|
pack-priv boolean eventEnabled(AWTEvent e) Overrides java. |
getAccessibleContext | back to summary |
---|---|
public AccessibleContext getAccessibleContext() Overrides java. Implements javax. Gets the
|
getActionCommand | back to summary |
---|---|
public String getActionCommand() Returns the command name of the action event fired by this button.
If the command name is
|
getActionListeners | back to summary |
---|---|
public synchronized ActionListener[] getActionListeners() Returns an array of all the action listeners registered on this button.
|
getLabel | back to summary |
---|---|
public String getLabel() Gets the label of this button.
|
getListeners | back to summary |
---|---|
public <T extends EventListener> T[] getListeners(Class<T> listenerType) Overrides java. Returns an array of all the objects currently registered
as
You can specify the ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));If no such listeners exist, this method returns an empty array.
|
paramString | back to summary |
---|---|
protected String paramString() Overrides java. Returns a string representing the state of this
|
processActionEvent | back to summary |
---|---|
protected void processActionEvent(ActionEvent e) Processes action events occurring on this button
by dispatching them to any registered
This method is not called unless action events are enabled for this button. Action events are enabled when one of the following occurs:
Note that if the event parameter is
|
processEvent | back to summary |
---|---|
protected void processEvent(AWTEvent e) Overrides java. Processes events on this button. If an event is
an instance of Note that if the event parameter is
|
readObject | back to summary |
---|---|
private void readObject(ObjectInputStream s) throws ClassNotFoundException, IOException, HeadlessException Hides java. Reads the
|
removeActionListener | back to summary |
---|---|
public synchronized void removeActionListener(ActionListener l) Removes the specified action listener so that it no longer receives action events from this button. Action events occur when a user presses or releases the mouse over this button. If l is null, no exception is thrown and no action is performed. Refer to AWT Threading Issues for details on AWT's threading model.
|
setActionCommand | back to summary |
---|---|
public void setActionCommand(String command) Sets the command name for the action event fired by this button. By default this action command is set to match the label of the button.
|
setLabel | back to summary |
---|---|
public void setLabel(String label) Sets the button's label to be the specified string.
|
writeObject | back to summary |
---|---|
private void writeObject(ObjectOutputStream s) throws IOException Hides java. Writes default serializable fields to stream. Writes
a list of serializable
|
Button
class. It provides an implementation of the
Java Accessibility API appropriate to button user-interface elements.
Modifier and Type | Field and Description |
---|---|
private static final long | serialVersionUID
Hides java. |
Access | Constructor and Description |
---|---|
protected |
Modifier and Type | Method and Description |
---|---|
public boolean | Returns: true if the action was performed; else false.zero-based index of actions i)Implements javax. |
public AccessibleAction | Returns: this objectOverrides javax. |
public int | Returns: 1, the number of Actions in this objectImplements javax. |
public String | getAccessibleActionDescription(int
zero-based index of the actions i)Implements javax. |
public String | Returns: the localized name of the object -- can be null if this object does not have a nameOverrides java. |
public AccessibleRole | Returns: an instance of AccessibleRole describing the role of the objectOverrides java. |
public AccessibleValue | Returns: this objectOverrides javax. |
public Number | Returns: An Integer of 0 if this isn't selected or an Integer of 1 if this is selected.Implements javax. |
public Number | Returns: An Integer of 0.Implements javax. |
public Number | Returns: An Integer of 0.Implements javax. |
public boolean | Returns: True if the value was set.the number to use for the value n)Implements javax. |
serialVersionUID | back to summary |
---|---|
private static final long serialVersionUID Hides java. Use serialVersionUID from JDK 1.3 for interoperability. |
AccessibleAWTButton | back to summary |
---|---|
protected AccessibleAWTButton() Constructs an |
doAccessibleAction | back to summary |
---|---|
public boolean doAccessibleAction(int i) Implements javax. Perform the specified Action on the object
|
getAccessibleAction | back to summary |
---|---|
public AccessibleAction getAccessibleAction() Overrides javax. Get the AccessibleAction associated with this object. In the implementation of the Java Accessibility API for this class, return this object, which is responsible for implementing the AccessibleAction interface on behalf of itself.
|
getAccessibleActionCount | back to summary |
---|---|
public int getAccessibleActionCount() Implements javax. Returns the number of Actions available in this object. The default behavior of a button is to have one action - toggle the button.
|
getAccessibleActionDescription | back to summary |
---|---|
public String getAccessibleActionDescription(int i) Implements javax. Return a description of the specified action of the object.
|
getAccessibleName | back to summary |
---|---|
public String getAccessibleName() Overrides java. Get the accessible name of this object.
|
getAccessibleRole | back to summary |
---|---|
public AccessibleRole getAccessibleRole() Overrides java. Get the role of this object.
|
getAccessibleValue | back to summary |
---|---|
public AccessibleValue getAccessibleValue() Overrides javax. Get the AccessibleValue associated with this object. In the implementation of the Java Accessibility API for this class, return this object, which is responsible for implementing the AccessibleValue interface on behalf of itself.
|
getCurrentAccessibleValue | back to summary |
---|---|
public Number getCurrentAccessibleValue() Implements javax. Get the value of this object as a Number.
|
getMaximumAccessibleValue | back to summary |
---|---|
public Number getMaximumAccessibleValue() Implements javax. Get the maximum value of this object as a Number.
|
getMinimumAccessibleValue | back to summary |
---|---|
public Number getMinimumAccessibleValue() Implements javax. Get the minimum value of this object as a Number.
|
setCurrentAccessibleValue | back to summary |
---|---|
public boolean setCurrentAccessibleValue(Number n) Implements javax. Set the value of this object as a Number.
|