java.awt

Class Button

Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, Serializable

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.
extends EventListener> T[] getListeners(Class listenerType)
Returns all registered EventListers of the given listenerType.
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.
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, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, 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, 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, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, 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, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, 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, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, 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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

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 Details

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.

addNotify

public void addNotify()
Notifies this button that it should create its native peer object.
Overrides:
addNotify in interface Component

extends EventListener> T[] getListeners

public extends EventListener> T[] getListeners(Class listenerType)
Returns all registered EventListers of the given listenerType. listenerType must be a subclass of EventListener, or a ClassClassException is thrown.
Overrides:
extends EventListener> T[] getListeners in interface 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

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 interface Component
Returns:
the associated context

getActionCommand

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

getActionListeners

public ActionListener[] getActionListeners()
Returns all added ActionListener objects.
Returns:
an array of listeners
Since:
1.4

getLabel

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

paramString

protected String paramString()
Returns a debugging string for this button.
Overrides:
paramString in interface Component
Returns:
A debugging string for this button.

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.

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 interface Component
Parameters:
event - The event to process.

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.

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.

setLabel

public void setLabel(String label)
Sets the label for this button to the specified value.
Parameters:
label - The new label for this button.

Button.java -- AWT button widget Copyright (C) 1999, 2002, 2004, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.