- All Implemented Interfaces:
- ImageObserver,- MenuContainer,- Serializable,- Accessible
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.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected classThis class implements accessibility support for theButtonclass.Nested classes/interfaces declared in class java.awt.ComponentComponent.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
- 
Field SummaryFields declared in class java.awt.ComponentaccessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserverABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds the specified action listener to receive action events from this button.voidCreates the peer of the button.Gets theAccessibleContextassociated with thisButton.Returns the command name of the action event fired by this button.Returns an array of all the action listeners registered on this button.getLabel()Gets the label of this button.<T extends EventListener>
 T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon thisButton.protected StringReturns a string representing the state of thisButton.protected voidProcesses action events occurring on this button by dispatching them to any registeredActionListenerobjects.protected voidProcesses events on this button.voidRemoves the specified action listener so that it no longer receives action events from this button.voidsetActionCommand(String command) Sets the command name for the action event fired by this button.voidSets the button's label to be the specified string.Methods declared in class java.awt.Componentaction, 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, getBaseline, getBaselineResizeBehavior, 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, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, revalidate, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
- 
Constructor Details- 
ButtonConstructs a button with an empty string for its label.- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
 
- 
ButtonConstructs a button with the specified label.- Parameters:
- label- a string label for the button, or- nullfor no label
- Throws:
- HeadlessException- if GraphicsEnvironment.isHeadless() returns true
- See Also:
 
 
- 
- 
Method Details- 
addNotifypublic 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.
- 
getLabelGets the label of this button.- Returns:
- the button's label, or nullif the button has no label.
- See Also:
 
- 
setLabelSets the button's label to be the specified string.- Parameters:
- label- the new label, or- nullif the button has no label.
- See Also:
 
- 
setActionCommandSets 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. If the string is- nullthen the action command is set to match the label of the button.
- Since:
- 1.1
- See Also:
 
- 
getActionCommandReturns the command name of the action event fired by this button. If the command name isnull(default) then this method returns the label of the button.- Returns:
- the action command name (or label) for this button
 
- 
addActionListenerAdds 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. - Parameters:
- l- the action listener
- Since:
- 1.1
- See Also:
 
- 
removeActionListenerRemoves 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. - Parameters:
- l- the action listener
- Since:
- 1.1
- See Also:
 
- 
getActionListenersReturns an array of all the action listeners registered on this button.- Returns:
- all of this button's ActionListeners or an empty array if no action listeners are currently registered
- Since:
- 1.4
- See Also:
 
- 
getListenersReturns an array of all the objects currently registered asFooListeners upon thisButton.FooListeners are registered using theaddFooListenermethod.You can specify the listenerTypeargument with a class literal, such asFooListener.class. For example, you can query aButton bfor 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.- Overrides:
- getListenersin class- Component
- Type Parameters:
- T- the type of the listeners
- Parameters:
- listenerType- the type of listeners requested; this parameter should specify an interface that descends from- java.util.EventListener
- Returns:
- an array of all objects registered as
          FooListeners on this button, or an empty array if no such listeners have been added
- Throws:
- ClassCastException- if- listenerTypedoesn't specify a class or interface that implements- java.util.EventListener
- Since:
- 1.3
- See Also:
 
- 
processEventProcesses events on this button. If an event is an instance ofActionEvent, this method invokes theprocessActionEventmethod. Otherwise, it invokesprocessEventon the superclass.Note that if the event parameter is nullthe behavior is unspecified and may result in an exception.- Overrides:
- processEventin class- Component
- Parameters:
- e- the event
- Since:
- 1.1
- See Also:
 
- 
processActionEventProcesses action events occurring on this button by dispatching them to any registeredActionListenerobjects.This method is not called unless action events are enabled for this button. Action events are enabled when one of the following occurs: - An ActionListenerobject is registered viaaddActionListener.
- Action events are enabled via enableEvents.
 Note that if the event parameter is nullthe behavior is unspecified and may result in an exception.- Parameters:
- e- the action event
- Since:
- 1.1
- See Also:
 
- An 
- 
paramStringReturns a string representing the state of thisButton. 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 benull.- Overrides:
- paramStringin class- Component
- Returns:
- the parameter string of this button
 
- 
getAccessibleContext@BeanProperty(expert=true, description="The AccessibleContext associated with this Button.") public AccessibleContext getAccessibleContext()Gets theAccessibleContextassociated with thisButton. For buttons, theAccessibleContexttakes the form of anAccessibleAWTButton. A newAccessibleAWTButtoninstance is created if necessary.- Specified by:
- getAccessibleContextin interface- Accessible
- Overrides:
- getAccessibleContextin class- Component
- Returns:
- an AccessibleAWTButtonthat serves as theAccessibleContextof thisButton
- Since:
- 1.3
 
 
-