Packages  This Package  Prev  Next  Index  

§1.2 Class Button

public  class  java.awt.Button
    extends  java.awt.Component  (II-§1.10)
{
        // Constructors
    public Button();	§1.2.1
    public Button(String  label);	§1.2.2

        // Methods
    public void addNotify();	§1.2.3
    public String getLabel();	§1.2.4
    protected String paramString();	§1.2.5
    public void setLabel(String  label);	§1.2.6
}
This class creates a labeled button. The application can cause some action to happen when the button is pushed. Below are three views of a "Quit" button in Solaris:

The first shows the button normally. The second shows the button when it has the input focus: the darkening of the outline lets the user know that this is an active object. The third shows the button when the user clicks the mouse over the button, and thus requests that the mouse's action(s) be performed.

When a button is pushed and released1, AWT sends an action event (II-§1.14.11) to the button. This event's target is the button, and its object is the string label of the button. An application should override the action method (II-§1.10.1) of the button or of one of its containing windows in order to cause some action to occur.


Constructors

Button

public Button()
Creates a button with no label.

Button

public Button(String label)
Creates a button with the indicated label.
Parameters:
label - a string label for the button

Methods

addNotify

public void addNotify()
This method calls the createButton method (II-§1.41.3) of the button's toolkit (II-§1.10.20) in order to create a ButtonPeer (II-§3.1) for this button. This peer allows the application to change the look of a button without changing its functionality.


Most applications do not call this method directly.
Overrides:
addNotify in class Component (II-§1.10.2).

getLabel

public String getLabel()
Returns:
the label of this button, or null if this button has no label.
See Also:
setLabel (II-§1.2.6).

paramString

protected String paramString()
Returns the parameter string representing the state of this button. This string is useful for debugging.
Returns:
the parameter string of this button.
Overrides:
paramString in class Component (II-§1.10.51).

setLabel

public void setLabel(String label)
Changes this button's label to be the String argument.
Parameters:
label - the new label, or null for no label
See Also:
getLabel (II-§1.2.4).

1 In Java 1.0, the AWT does not send mouse or focus events to a button. In Java 1.1, the AWT sends the button all mouse, keyboard, and focus events that occur over it.

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com