java.awt
Class Button

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Button
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, Serializable

public class Button
extends Component
implements Accessible

Unsafe:

See Also:
Serialized Form

Field Summary
(package private)  String actionCommand
           
(package private)  ActionListener actionListener
           
private static String base
           
private  int buttonSerializedDataVersion
           
(package private)  String label
           
private static int nameCounter
           
private static long serialVersionUID
           
 
Fields inherited from class java.awt.Component
accessibleContext, actionListenerK, adjustmentListenerK, appContext, background, BOTTOM_ALIGNMENT, bufferStrategy, CENTER_ALIGNMENT, componentListener, componentListenerK, componentOrientation, containerListenerK, cursor, dropTarget, enabled, eventMask, focusListener, focusListenerK, focusTraversalKeys, font, foreground, graphicsConfig, height, hierarchyBoundsListener, hierarchyBoundsListenerK, hierarchyListener, hierarchyListenerK, ignoreRepaint, incRate, inputMethodListener, inputMethodListenerK, isInc, isPacked, itemListenerK, keyListener, keyListenerK, LEFT_ALIGNMENT, locale, LOCK, metrics, minSize, mouseListener, mouseListenerK, mouseMotionListener, mouseMotionListenerK, mouseWheelListener, mouseWheelListenerK, newEventsOnly, ownedWindowK, parent, peer, peerFont, popups, prefSize, RIGHT_ALIGNMENT, textListenerK, TOP_ALIGNMENT, valid, visible, width, windowClosingException, windowFocusListenerK, windowListenerK, windowStateListenerK, x, y
 
Constructor Summary
Button()
          Suppressed: Constructs a Button with no label.
Button(String label)
          Suppressed: Constructs a Button with the specified label.
 
Method Summary
 void addActionListener(ActionListener l)
          Suppressed: Adds the specified action listener to receive action events from this button.
 void addNotify()
          Suppressed: Creates the peer of the button.
(package private)  String constructComponentName()
          Construct a name for this component.
(package private)  boolean eventEnabled(AWTEvent e)
           
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this Button.
 String getActionCommand()
          Suppressed: Returns the command name of the action event fired by this button.
 ActionListener[] getActionListeners()
          Suppressed: Returns an array of all the action listeners registered on this button.
 String getLabel()
          Suppressed: Gets the label of this button.
 EventListener[] getListeners(Class listenerType)
          Suppressed: Returns an array of all the objects currently registered as FooListeners upon this Button.
private static void initIDs()
          Initialize JNI field and method IDs for fields that may be accessed from C.
protected  String paramString()
          Returns a string representing the state of this Button.
protected  void processActionEvent(ActionEvent e)
          Processes action events occurring on this button by dispatching them to any registered ActionListener objects.
protected  void processEvent(AWTEvent e)
          Processes events on this button.
private  void readObject(ObjectInputStream s)
          Reads the ObjectInputStream and if it isn't null adds a listener to receive action events fired by the button.
 void removeActionListener(ActionListener l)
          Suppressed: Removes the specified action listener so that it no longer receives action events from this button.
 void setActionCommand(String command)
          Suppressed: Sets the command name for the action event fired by this button.
 void setLabel(String label)
          Suppressed: Sets the button's label to be the specified string.
private  void writeObject(ObjectOutputStream s)
          Writes default serializable fields to stream.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addPropertyChangeListener, addPropertyChangeListener, adjustListeningChildrenOnParent, applyComponentOrientation, areFocusTraversalKeysSet, areInputMethodsEnabled, autoProcessMouseWheel, autoTransferFocus, bounds, checkGD, checkImage, checkImage, checkWindowClosingException, clearCurrentFocusCycleRootOnHide, clearMostRecentFocusOwnerOnHide, coalesceEvents, contains, contains, containsFocus, countHierarchyMembers, createBufferStrategy, createBufferStrategy, createChildHierarchyEvents, createHierarchyEvents, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, dispatchEventImpl, dispatchMouseWheelToAncestor, doLayout, enable, enable, enableEvents, enableInputMethods, eventTypeEnabled, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleIndexInParent, getAccessibleStateSet, getAlignmentX, getAlignmentY, getBackBuffer, getBackground, getBounds, getBounds, getBufferStrategy, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys_NoIDCheck, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont_NoClientCode, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen_NoTreeLock, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getNativeContainer, getParent_NoClientCode, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getToolkitImpl, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, initializeFocusTraversalKeys, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isEnabledImpl, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusTraversableOverridden, isFontSet, isForegroundSet, isLightweight, isOpaque, isRecursivelyVisible, isShowing, isValid, isVisible, iterate, keyDown, keyUp, layout, lightweightPaint, lightweightPrint, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, nextFocusHelper, numListening, paint, paintAll, paintHeavyweightComponents, postEvent, postsOldMouseEvents, preferredSize, prepareImage, prepareImage, print, printAll, printHeavyweightComponents, 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, requestFocusHelper, requestFocusInWindow, requestFocusInWindow, resetGC, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys_NoIDCheck, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setGCFromPeer, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocus, transferFocusBackward, transferFocusUpCycle, update, updateCursorImmediately, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

label

String label

actionCommand

String actionCommand

actionListener

transient ActionListener actionListener

base

private static final String base

nameCounter

private static int nameCounter

serialVersionUID

private static final long serialVersionUID

buttonSerializedDataVersion

private int buttonSerializedDataVersion
Constructor Detail

Button

public Button()
       throws HeadlessException
Suppressed: Constructs a Button with no label.

See Also:
java.awt.GraphicsEnvironment#isHeadless

Button

public Button(String label)
       throws HeadlessException
Suppressed: Constructs a Button with the specified label.

Parameters:
label - A string label for the button.
See Also:
java.awt.GraphicsEnvironment#isHeadless
Method Detail

initIDs

private static void initIDs()
Initialize JNI field and method IDs for fields that may be accessed from C.


constructComponentName

String constructComponentName()
Construct a name for this component. Called by getName() when the name is null.

Overrides:
constructComponentName in class Component

addNotify

public void addNotify()
Suppressed: Creates the peer of the button. The button's peer allows the application to change the look of the button without changing its functionality.

Overrides:
addNotify in class Component
See Also:
java.awt.Toolkit#createButton(java.awt.Button), java.awt.Component#getToolkit()

getLabel

public String getLabel()
Suppressed: Gets the label of this button.

Returns:
the button's label, or null if the button has no label.
See Also:
java.awt.Button#setLabel

setLabel

public void setLabel(String label)
Suppressed: Sets the button's label to be the specified string.

Parameters:
label - the new label, or null if the button has no label.
See Also:
java.awt.Button#getLabel

setActionCommand

public void setActionCommand(String command)
Suppressed: Sets 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 null then the action command is set to match the label of the button.
Since:
JDK1.1
See Also:
java.awt.event.ActionEvent

getActionCommand

public String getActionCommand()
Suppressed: Returns the command name of the action event fired by this button. If the command name is null (default) then this method returns the label of the button.


addActionListener

public void addActionListener(ActionListener l)
Suppressed: Adds 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.

Parameters:
l - the action listener
Since:
JDK1.1
See Also:
removeActionListener(java.awt.event.ActionListener), getActionListeners(), java.awt.event.ActionListener

removeActionListener

public void removeActionListener(ActionListener l)
Suppressed: Removes 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.

Parameters:
l - the action listener
Since:
JDK1.1
See Also:
addActionListener(java.awt.event.ActionListener), getActionListeners(), java.awt.event.ActionListener

getActionListeners

public ActionListener[] getActionListeners()
Suppressed: Returns 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:
addActionListener(java.awt.event.ActionListener), removeActionListener(java.awt.event.ActionListener), java.awt.event.ActionListener

getListeners

public EventListener[] getListeners(Class listenerType)
Suppressed: Returns an array of all the objects currently registered as FooListeners upon this Button. FooListeners 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.

Overrides:
getListeners in class Component
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
Since:
1.3
See Also:
getActionListeners()

eventEnabled

boolean eventEnabled(AWTEvent e)
Overrides:
eventEnabled in class Component

processEvent

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

Overrides:
processEvent in class Component
Parameters:
e - the event
Since:
JDK1.1
See Also:
java.awt.event.ActionEvent, java.awt.Button#processActionEvent

processActionEvent

protected void processActionEvent(ActionEvent e)
Processes action events occurring on this button by dispatching them to any registered 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:

Note that if the event parameter is null the behavior is unspecified and may result in an exception.

Parameters:
e - the action event
Since:
JDK1.1
See Also:
java.awt.event.ActionListener, java.awt.Button#addActionListener, java.awt.Component#enableEvents

paramString

protected String paramString()
Returns a string representing the state of this 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.

Overrides:
paramString in class Component
Returns:
the parameter string of this button

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
Writes default serializable fields to stream. Writes a list of serializable ActionListeners as optional data. The non-serializable ActionListeners are detected and no attempt is made to serialize them.

Parameters:
s - the ObjectOutputStream to write
IOException
See Also:
AWTEventMulticaster.save(ObjectOutputStream, String, EventListener), java.awt.Component.actionListenerK, readObject(java.io.ObjectInputStream)

readObject

private void readObject(ObjectInputStream s)
                 throws ClassNotFoundException,
                        IOException,
                        HeadlessException
Reads the ObjectInputStream and if it isn't null adds a listener to receive action events fired by the button. Unrecognized keys or values will be ignored.

Parameters:
s - the ObjectInputStream to read
ClassNotFoundException
IOException
HeadlessException
See Also:
removeActionListener(), addActionListener(), java.awt.GraphicsEnvironment#isHeadless, writeObject(java.io.ObjectOutputStream)

getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: Gets the AccessibleContext associated with this Button. For buttons, the AccessibleContext takes the form of an AccessibleAWTButton. A new AccessibleAWTButton instance is created if necessary.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class Component
Returns:
an AccessibleAWTButton that serves as the AccessibleContext of this Button


comments?