All Packages Class Hierarchy This Package Previous Next Index
Class java.awt.Button
java.lang.Object
|
+----java.awt.Component
|
+----java.awt.Button
- public class Button
- extends Component
This class creates a labeled button. The application can cause
some action to happen when the button is pushed. This image
depicts three views of a "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.
- See Also:
- ActionEvent, ActionListener, processMouseEvent, addMouseListener
-
Button()
- Constructs a Button with no label.
-
Button(String)
- Constructs a Button with the specified label.
-
addActionListener(ActionListener)
- Adds the specified action listener to receive action events from
this button.
-
addNotify()
- Creates the peer of the button.
-
getActionCommand()
- Returns the command name of the action event fired by this button.
-
getLabel()
- Gets the label of this button.
-
paramString()
- Returns the parameter string representing the state of this
button.
-
processActionEvent(ActionEvent)
-
Processes action events occurring on this button
by dispatching them to any registered
ActionListener
objects.
-
processEvent(AWTEvent)
- Processes events on this button.
-
removeActionListener(ActionListener)
- Removes the specified action listener so that it no longer
receives action events from this button.
-
setActionCommand(String)
- Sets the command name for the action event fired
by this button.
-
setLabel(String)
- Sets the button's label to be the specified string.
Button
public Button()
- Constructs a Button with no label.
Button
public Button(String label)
- Constructs a Button with the specified label.
- Parameters:
- label - A string label for the button.
addNotify
public void addNotify()
- Creates the peer of the button. The button's peer allows the
application to change the look of the button without changing
its functionality.
- Overrides:
- addNotify in class Component
- See Also:
- createButton, getToolkit
getLabel
public String getLabel()
- Gets the label of this button.
- Returns:
- the button's label, or
null
if the button has no label.
- See Also:
- setLabel
setLabel
public synchronized void setLabel(String label)
- Sets the button's label to be the specified string.
- Parameters:
- label - the new label, or
null
if the button has no label.
- See Also:
- getLabel
setActionCommand
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.
- Parameters:
- command - A string used to set the button's
action command.
- See Also:
- ActionEvent
getActionCommand
public String getActionCommand()
- Returns the command name of the action event fired by this button.
addActionListener
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.
- Parameters:
- l - the action listener.
- See Also:
- ActionListener, removeActionListener
removeActionListener
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.
- Parameters:
- l - the action listener.
- See Also:
- ActionListener, addActionListener
processEvent
protected void processEvent(AWTEvent e)
- 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.
- Parameters:
- e - the event.
- Overrides:
- processEvent in class Component
- See Also:
- ActionEvent, processActionEvent
processActionEvent
protected void processActionEvent(ActionEvent e)
- 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:
- An
ActionListener
object is registered
via addActionListener
.
- Action events are enabled via
enableEvents
.
- Parameters:
- e - the action event.
- See Also:
- ActionListener, addActionListener, enableEvents
paramString
protected String paramString()
- Returns the parameter string representing the state of this
button. This string is useful for debugging.
- Returns:
- the parameter string of this button.
- Overrides:
- paramString in class Component
All Packages Class Hierarchy This Package Previous Next Index
Submit a bug or feature - Version 1.1.8 of Java Platform API Specification
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.
Copyright 1995-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.