Listener Method

Listener Method


// Inner class is OK as long as it is public
public class TheButtons extends CustomComponent {
    Button thebutton;
    Button secondbutton;

    public TheButtons() {
        thebutton = new Button ("Do not push this button");
        thebutton.addListener(Button.ClickEvent.class, this,
                              "theButtonClick");
        
        secondbutton = new Button ("I am a button too");
        secondbutton.addListener(Button.ClickEvent.class, this,
                                 "secondButtonClick");

        Layout root = new HorizontalLayout(); 
        root.addComponent(thebutton);
        root.addComponent (secondbutton);
        setCompositionRoot(root);
    }
    
    public void theButtonClick (Button.ClickEvent event) {
        thebutton.setCaption ("Do not push this button again");
    }

    public void secondButtonClick (Button.ClickEvent event) {
        secondbutton.setCaption ("I am not a number!");
    }
}
    
public void methodlistener(VerticalLayout layout) {
    TheButtons buttons = new TheButtons();
    layout.addComponent(buttons);