java.awt
Class Button

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Button
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class Button
extends Component
implements Serializable, Accessible

This class provides a button widget for the AWT.

See Also:
Serialized Form

Nested Class Summary
protected  class Button.AccessibleAWTButton
           
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Button()
          Initializes a new instance of Button with no label.
Button(String label)
          Initializes a new instance of Button with the specified label.
 
Method Summary
 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>
T[]
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.
 
Methods inherited from class java.awt.Component
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Button

public Button()
Initializes a new instance of Button with no label.

Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() returns true

Button

public Button(String label)
Initializes a new instance of Button with the specified label. The action command name is also initialized to this value.

Parameters:
label - The label to display on the button.
Throws:
HeadlessException - If GraphicsEnvironment.isHeadless() returns true
Method Detail

getLabel

public String getLabel()
Returns the label for this button.

Returns:
The label for this button.

setLabel

public void setLabel(String label)
Sets the label for this button to the specified value.

Parameters:
label - The new label for this button.

getActionCommand

public String getActionCommand()
Returns the action command name for this button.

Returns:
The action command name for this button.

setActionCommand

public void setActionCommand(String actionCommand)
Sets the action command name for this button to the specified value.

Parameters:
actionCommand - The new action command name.

addActionListener

public void addActionListener(ActionListener listener)
Adds a new entry to the list of listeners that will receive action events from this button.

Parameters:
listener - The listener to add.

removeActionListener

public void removeActionListener(ActionListener listener)
Removes the specified listener from the list of listeners that will receive action events from this button.

Parameters:
listener - The listener to remove.

getActionListeners

public ActionListener[] getActionListeners()
Returns all added ActionListener objects.

Returns:
an array of listeners
Since:
1.4

getListeners

public <T extends EventListener> T[] getListeners(Class<T> listenerType)
Returns all registered EventListers of the given listenerType. listenerType must be a subclass of EventListener, or a ClassClassException is thrown.

Overrides:
getListeners in class Component
Parameters:
listenerType - the listener type to return
Returns:
an array of listeners
Throws:
ClassCastException - If listenerType doesn't specify a class or interface that implements @see java.util.EventListener.
Since:
1.3
See Also:
Component.getComponentListeners(), Component.getFocusListeners(), Component.getHierarchyListeners(), Component.getHierarchyBoundsListeners(), Component.getKeyListeners(), Component.getMouseListeners(), Component.getMouseMotionListeners(), Component.getMouseWheelListeners(), Component.getInputMethodListeners(), Component.getPropertyChangeListeners()

addNotify

public void addNotify()
Notifies this button that it should create its native peer object.

Overrides:
addNotify in class Component
See Also:
Component.isDisplayable(), Component.removeNotify()

processEvent

protected void processEvent(AWTEvent event)
Processes an event for this button. If the specified event is an instance of 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.

Overrides:
processEvent in class Component
Parameters:
event - The event to process.
See Also:
Component.processComponentEvent(ComponentEvent), Component.processFocusEvent(FocusEvent), Component.processKeyEvent(KeyEvent), Component.processMouseEvent(MouseEvent), Component.processMouseMotionEvent(MouseEvent), Component.processInputMethodEvent(InputMethodEvent), Component.processHierarchyEvent(HierarchyEvent), Component.processMouseWheelEvent(MouseWheelEvent)

processActionEvent

protected void processActionEvent(ActionEvent event)
This method dispatches an action event for this button to any registered listeners.

Parameters:
event - The event to process.

paramString

protected String paramString()
Returns a debugging string for this button.

Overrides:
paramString in class Component
Returns:
A debugging string for this button.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this Button. The context is created, if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Component
Returns:
the associated context