Up Next
Go up to Interface Components
Go forward to Choices

Buttons


new Button();
new Button( some-button-label );

As described above, "Button" is both the name of the "class" of user interface components we call buttons and the name of a constructor method that can be used to construct buttons. Normally, one provides the "Button" constructor method a single text string as a parameter. This string is then used as a label for the button. Since it is possible to set a button's label later using the "setLabel" method, one may also use the "Button" constructor without providing any parameters to produce a label-less button.

Button Event Handlers


void buttonClick() { ... }
void buttonClick( Button whichone ) { ... }

The only event handling method associated with buttons is "buttonClick". If this method is defined in an applet, it will be invoked whenever a user clicks on any button displayed in the applet's screen region.

"buttonClick" can be defined to expect the browser to pass it a single parameter when it is invoked. This parameter will be the button that was clicked and must therefore be declared to be of the type "Button". This parameter can be used to decide how to react appropriately when several different buttons have been included in an applet's display.

Button Methods


somebutton.setLabel( some-text-string );

The "setLabel" method associated with a button can be used to change the text label displayed in the button.


somebutton.getLabel( some-text-string )

The "getLabel" method associated with a button can be used to determine the string currently appearing as a button's label.


Up Next