java.lang.Object java.awt.Component java.awt.Button
public class Button
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.
ActionEvent
, ActionListener
, Component.processMouseEvent(java.awt.event.MouseEvent)
, Component.addMouseListener(java.awt.event.MouseListener)
, Serialized Form
Button()
Button(String label)
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
Button
public Button() throws HeadlessException
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true
GraphicsEnvironment.isHeadless()
public Button(String label) throws HeadlessException
label
- a string label for the button, or null
for no label
HeadlessException
- if GraphicsEnvironment.isHeadless() returns true
GraphicsEnvironment.isHeadless()
public void addNotify()
addNotify
in class Component
Toolkit.createButton(java.awt.Button)
, Component.getToolkit()
public String getLabel()
null
if the button has no label.
setLabel(java.lang.String)
public void setLabel(String label)
label
- the new label, or null
if the button has no label.
getLabel()
public void setActionCommand(String command)
command
- a string used to set the button's action command. If the string is null
then the action command is set to match the label of the button.
ActionEvent
public String getActionCommand()
null
(default) then this method returns the label of the button.
public void addActionListener(ActionListener l)
l
- the action listener
removeActionListener(java.awt.event.ActionListener)
, getActionListeners()
, ActionListener
public void removeActionListener(ActionListener l)
l
- the action listener
addActionListener(java.awt.event.ActionListener)
, getActionListeners()
, ActionListener
public ActionListener[] getActionListeners()
ActionListener
s or an empty array if no action listeners are currently registered
addActionListener(java.awt.event.ActionListener)
, removeActionListener(java.awt.event.ActionListener)
, ActionListener
public <T extends EventListener> T[] getListeners(Class<T> listenerType)
FooListener
s upon this Button
. FooListener
s 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 Button
b
for its action listeners with the following code:
ActionListener[] als = (ActionListener[])(b.getListeners(ActionListener.class));If no such listeners exist, this method returns an empty array.
getListeners
in class Component
listenerType
- the type of listeners requested; this parameter should specify an interface that descends from java.util.EventListener
FooListener
s on this button, or an empty array if no such listeners have been added
ClassCastException
- if listenerType
doesn't specify a class or interface that implements java.util.EventListener
getActionListeners()
protected void processEvent(AWTEvent e)
ActionEvent
, this method invokes the processActionEvent
method. Otherwise, it invokes processEvent
on the superclass.
Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
processEvent
in class Component
e
- the event
ActionEvent
, processActionEvent(java.awt.event.ActionEvent)
protected void processActionEvent(ActionEvent e)
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:
ActionListener
object is registered via addActionListener
.enableEvents
.Note that if the event parameter is null
the behavior is unspecified and may result in an exception.
e
- the action event
ActionListener
, addActionListener(java.awt.event.ActionListener)
, Component.enableEvents(long)
protected String paramString()
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
.
paramString
in class Component
public AccessibleContext getAccessibleContext()
AccessibleContext
associated with this Button
. For buttons, the AccessibleContext
takes the form of an AccessibleAWTButton
. A new AccessibleAWTButton
instance is created if necessary.
getAccessibleContext
in interface Accessible
getAccessibleContext
in class Component
AccessibleAWTButton
that serves as the AccessibleContext
of this Button
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4