| public class java.awt Button
|
Java SE 6 |
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.
| version | 1.82 07/11/06 |
| since | JDK1.0 |
| See also | java.awt.event.ActionEvent, java.awt.event.ActionListener, processMouseEvent, addMouseListener |
| Constructors | |||||||
|---|---|---|---|---|---|---|---|
| public | Button() throws HeadlessException Details
Constructs a button with an empty string for its label.
| ||||||
| public | Button(String label) throws HeadlessException Details
Constructs a button with the specified label.
| ||||||
| Methods | |||||||
|---|---|---|---|---|---|---|---|
| public void | addActionListener(ActionListener l) Details
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.
| ||||||
| public void | addNotify() Details
Creates the peer of the button. The button's peer allows the
application to change the look of the button without changing
its functionality.
| ||||||
| protected String | paramString() Details
Returns a string representing the state of this Button.
This method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null.
| ||||||
| protected void | processActionEvent(ActionEvent e) Details
Processes action events occurring on this button
by dispatching them to any registered
ActionListener objects.
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
| ||||||
| protected void | processEvent(AWTEvent e) Details
Processes events on this button. If an event is
an instance of ActionEvent, this method invokes
the processActionEvent method. Otherwise,
it invokes processEvent on the superclass.
Note that if the event parameter is
| ||||||
| public void | removeActionListener(ActionListener l) Details
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.
| ||||||
| Properties | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| public AccessibleContext | getAccessibleContext() Details
Gets the AccessibleContext associated with
this Button. For buttons, the
AccessibleContext takes the form of an
AccessibleAWTButton.
A new AccessibleAWTButton instance is
created if necessary.
| ||||||||||
| public void | setActionCommand(String command) Details
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.
| ||||||||||
| public String | getActionCommand() Returns the command name of the action event fired by this button. If the command name is null (default) then this method
returns the label of the button.
| ||||||||||
| public ActionListener[] | getActionListeners() Details
Returns an array of all the action listeners
registered on this button.
| ||||||||||
| public void | setLabel(String label) Details
Sets the button's label to be the specified string.
| ||||||||||
| public String | getLabel() Details
Gets the label of this button.
| ||||||||||
| public EventListener[]<T> | getListeners(Class listenerType) Details
Returns an array of all the objects currently registered
as FooListeners
upon this Button.
FooListeners are registered using the
addFooListener method.
You can specify the ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));If no such listeners exist, this method returns an empty array.
| ||||||||||
| About DocWeb · Bundles · Export · Export All | Top 10 · Statistics · Login |
| About Sun · Contact · Privacy · Terms of Use · Trademarks | Java SE 6 · Copyright © 1994-2013 Sun Microsystems, Inc.All rights reserved. Use is subject to license terms |
![]() |
![]() |
|