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() 方法来区分不同的按钮。
本文详细介绍了Vaadin Web应用中Button按钮的使用方法及事件监听机制,通过实例展示了如何实现Button的点击事件响应,并讨论了在多Button场景下使用统一Listener的技巧。

5001

被折叠的 条评论
为什么被折叠?



