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

jerry VaadinWeb 2015年11月25日 收藏

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

  1. public class TheButton extends CustomComponent
  2. implements Button.ClickListener {
  3. Button thebutton;
  4.  
  5. public TheButton() {
  6. // Create a Button with the given caption.
  7. thebutton = new Button ("Do not push this button");
  8.  
  9. // Listen for ClickEvents.
  10. thebutton.addListener(this);
  11.  
  12. setCompositionRoot(thebutton);
  13. }
  14.  
  15. /** Handle click events for the button. */
  16. public void buttonClick (Button.ClickEvent event) {
  17. thebutton.setCaption ("Do not push this button again");
  18. }}

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