Vaadin Web应用开发教程(15):UI组件-Button

来源:互联网 发布:安安电子狗软件 编辑:程序博客网 时间:2024/04/23 21:42

Button 按钮,在前面Vaadin Web应用开发教程(5):Vaadin Web应用的基本组成部分 中介绍事件处理时已经对Button的用法做了说明。当用户点击按钮时会触发Button.ClickEvent ,可以使用 Button.ClickListener 来侦听这个事件。

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 click events for the button. */    public void buttonClick (Button.ClickEvent event) {        thebutton.setCaption ("Do not push this button again");    }}


为多个按钮使用同一个Listener时,可以通过Event的getButton() 方法来区分不同的按钮。

 

原创粉丝点击