The Button
is the primary user interface
component that is normally used for finalizing input and initiating
some action. When the user clicks a button, a
Button.ClickEvent
is emitted. A listener that
inherits the Button.ClickListener
interface
can handle clicks with the buttonClick()
method.
public class TheButton extends CustomComponent implements Button.ClickListener { Button thebutton; public TheButton() { /* Create a Button with the given caption. */ thebutton = new Button ("Do not push this button"); /* Listen for ClickEvents. */ thebutton.addListener(this); setCompositionRoot(thebutton); } /** Handle button click events from the button. */ public void buttonClick (Button.ClickEvent event) { thebutton.setCaption ("Do not push this button again"); } }
As a user interface often has several buttons, you can differentiate
between them either by comparing the Button
object reference returned by the getButton()
method of Button.ClickEvent
to a kept
reference or by using a separate listener method for each button. The
listening object and method can be given to the constructor. For a
detailed description of these patterns together with some examples,
please see Section 2.4, “Events and Listeners”.
.i-button { }
The exact CSS style name can be different if a Button
has the switchMode
attribute enabled. See the
alternative CSS styles below.