Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Button

Constructors , Methods , Footnotes

public  class  java.awt.Button
    extends  java.awt.Component  
{
        // Constructors
    public Button();	
    public Button(String  label);	

        // Methods
    public void addNotify();	
    public String getLabel();	
    protected String paramString();	
    public void setLabel(String  label);	
}

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 released(1), AWT sends an action event 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 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.

ParameterDescription
label a string label for the button


Methods


addNotify

public void addNotify() 

This method calls the createButton method of the button's toolkit in order to create a ButtonPeer 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 .


getLabel

public String getLabel() 

Return Value:

Returns the label of this button, or null if this button has no label.

See Also: setLabel .


paramString

protected String paramString() 

Returns the parameter string representing the state of this button. This string is useful for debugging.

Return Value:

Returns the parameter string of this button.

Overrides:

paramString in class Component .


setLabel

public void setLabel(String  label) 

Changes this button's label to be the String argument.

ParameterDescription
label the new label, or null for no label

See Also: getLabel .


Footnotes

(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.

Top© 1996 Sun Microsystems, Inc. All rights reserved.