当前位置:编程学习 > 网站相关 >>

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

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

[java]
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"); 
    }} 

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() 方法来区分不同的按钮。
\

 作者:mapdigit
 


补充:Web开发 , 其他 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,