java.awt
public class Button extends Component implements Serializable, Accessible
Modifier and Type | Class and Description |
---|---|
protected class |
Button.AccessibleAWTButton |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor and Description |
---|
Button()
Initializes a new instance of
Button with no label. |
Button(String label)
Initializes a new instance of
Button with the specified
label. |
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(ActionListener listener)
Adds a new entry to the list of listeners that will receive
action events from this button.
|
void |
addNotify()
Notifies this button that it should create its native peer object.
|
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext associated with this
Button . |
String |
getActionCommand()
Returns the action command name for this button.
|
ActionListener[] |
getActionListeners()
Returns all added
ActionListener objects. |
String |
getLabel()
Returns the label for this button.
|
<T extends EventListener> |
getListeners(Class<T> listenerType)
Returns all registered EventListers of the given listenerType.
|
protected String |
paramString()
Returns a debugging string for this button.
|
protected void |
processActionEvent(ActionEvent event)
This method dispatches an action event for this button to any
registered listeners.
|
protected void |
processEvent(AWTEvent event)
Processes an event for this button.
|
void |
removeActionListener(ActionListener listener)
Removes the specified listener from the list of listeners that will
receive action events from this button.
|
void |
setActionCommand(String actionCommand)
Sets the action command name for this button to the specified value.
|
void |
setLabel(String label)
Sets the label for this button to the specified value.
|
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
public Button()
Button
with no label.HeadlessException
- If GraphicsEnvironment.isHeadless()
returns truepublic Button(String label)
Button
with the specified
label. The action command name is also initialized to this value.label
- The label to display on the button.HeadlessException
- If GraphicsEnvironment.isHeadless()
returns truepublic String getLabel()
public void setLabel(String label)
label
- The new label for this button.public String getActionCommand()
public void setActionCommand(String actionCommand)
actionCommand
- The new action command name.public void addActionListener(ActionListener listener)
listener
- The listener to add.public void removeActionListener(ActionListener listener)
listener
- The listener to remove.public ActionListener[] getActionListeners()
ActionListener
objects.public <T extends EventListener> T[] getListeners(Class<T> listenerType)
getListeners
in class Component
listenerType
- the listener type to returnClassCastException
- If listenerType doesn't specify a class or
interface that implements @see java.util.EventListener.Component.getComponentListeners()
,
Component.getFocusListeners()
,
Component.getHierarchyListeners()
,
Component.getHierarchyBoundsListeners()
,
Component.getKeyListeners()
,
Component.getMouseListeners()
,
Component.getMouseMotionListeners()
,
Component.getMouseWheelListeners()
,
Component.getInputMethodListeners()
,
Component.getPropertyChangeListeners()
public void addNotify()
addNotify
in class Component
Component.isDisplayable()
,
Component.removeNotify()
protected void processEvent(AWTEvent event)
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.processEvent
in class Component
event
- The event to process.Component.processComponentEvent(ComponentEvent)
,
Component.processFocusEvent(FocusEvent)
,
Component.processKeyEvent(KeyEvent)
,
Component.processMouseEvent(MouseEvent)
,
Component.processMouseMotionEvent(MouseEvent)
,
Component.processInputMethodEvent(InputMethodEvent)
,
Component.processHierarchyEvent(HierarchyEvent)
,
Component.processMouseWheelEvent(MouseWheelEvent)
protected void processActionEvent(ActionEvent event)
event
- The event to process.protected String paramString()
paramString
in class Component
public AccessibleContext getAccessibleContext()
Button
.
The context is created, if necessary.getAccessibleContext
in interface Accessible
getAccessibleContext
in class Component