Methods Summary |
---|
public synchronized void | addActionListener(java.awt.event.ActionListener l)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.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.add(actionListener, l);
newEventsOnly = true;
|
public 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.
synchronized(getTreeLock()) {
if (peer == null)
peer = getToolkit().createButton(this);
super.addNotify();
}
|
java.lang.String | constructComponentName()Construct a name for this component. Called by getName() when the
name is null.
synchronized (getClass()) {
return base + nameCounter++;
}
|
boolean | eventEnabled(java.awt.AWTEvent e)
if (e.id == ActionEvent.ACTION_PERFORMED) {
if ((eventMask & AWTEvent.ACTION_EVENT_MASK) != 0 ||
actionListener != null) {
return true;
}
return false;
}
return super.eventEnabled(e);
|
public javax.accessibility.AccessibleContext | getAccessibleContext()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.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTButton();
}
return accessibleContext;
|
public java.lang.String | getActionCommand()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.
return (actionCommand == null? label : actionCommand);
|
public synchronized java.awt.event.ActionListener[] | getActionListeners()Returns an array of all the action listeners
registered on this button.
return (ActionListener[]) (getListeners(ActionListener.class));
|
public java.lang.String | getLabel()Gets the label of this button.
return label;
|
public T[] | getListeners(java.lang.Class listenerType)Returns an array of all the objects currently registered
as FooListener s
upon this Button .
FooListener s 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.
EventListener l = null;
if (listenerType == ActionListener.class) {
l = actionListener;
} else {
return super.getListeners(listenerType);
}
return AWTEventMulticaster.getListeners(l, listenerType);
|
private static native void | initIDs()Initialize JNI field and method IDs for fields that may be
accessed from C.
|
protected java.lang.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 .
return super.paramString() + ",label=" + label;
|
protected void | processActionEvent(java.awt.event.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:
- An
ActionListener object is registered
via addActionListener .
- Action events are enabled via
enableEvents .
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
ActionListener listener = actionListener;
if (listener != null) {
listener.actionPerformed(e);
}
|
protected void | processEvent(java.awt.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.
if (e instanceof ActionEvent) {
processActionEvent((ActionEvent)e);
return;
}
super.processEvent(e);
|
private void | readObject(java.io.ObjectInputStream s)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.
GraphicsEnvironment.checkHeadless();
s.defaultReadObject();
Object keyOrNull;
while(null != (keyOrNull = s.readObject())) {
String key = ((String)keyOrNull).intern();
if (actionListenerK == key)
addActionListener((ActionListener)(s.readObject()));
else // skip value for unrecognized key
s.readObject();
}
|
public synchronized void | removeActionListener(java.awt.event.ActionListener l)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.
Refer to AWT Threading Issues for details on AWT's threading model.
if (l == null) {
return;
}
actionListener = AWTEventMulticaster.remove(actionListener, l);
|
public void | setActionCommand(java.lang.String command)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.
actionCommand = command;
|
public void | setLabel(java.lang.String label)Sets the button's label to be the specified string.
boolean testvalid = false;
synchronized (this) {
if (label != this.label && (this.label == null ||
!this.label.equals(label))) {
this.label = label;
ButtonPeer peer = (ButtonPeer)this.peer;
if (peer != null) {
peer.setLabel(label);
}
testvalid = true;
}
}
// This could change the preferred size of the Component.
if (testvalid && valid) {
invalidate();
}
|
private void | writeObject(java.io.ObjectOutputStream s)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.
s.defaultWriteObject();
AWTEventMulticaster.save(s, actionListenerK, actionListener);
s.writeObject(null);
|