blob: 9b77e7855ac39e0eef55da01c915adaa64ff8a9e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
@ITMillApache2LicenseForJavaFiles@
*/
package com.vaadin.tests.book;
import com.vaadin.ui.AbstractComponentContainer;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
/** This example demonstrates the use of inline classes for event listeners. */
public class TheButtons3 {
Button thebutton; /* This component is stored as a member variable. */
/** Creates two buttons in given container. */
public TheButtons3(AbstractComponentContainer container) {
thebutton = new Button("Do not push this button");
thebutton.addListener(new Button.ClickListener() {
/*
* Define the method in the local class to handle the click.
*/
public void buttonClick(ClickEvent event) {
thebutton.setCaption("Do not push this button again");
}
});
container.addComponent(thebutton);
/*
* Have the second button as a local variable in the constructor. Only
* "final" local variables can be accessed from an anonymous class.
*/
final Button secondbutton = new Button("I am a button too");
secondbutton.addListener(new Button.ClickListener() {
/*
* Define the method in the local class to handle the click.
*/
public void buttonClick(ClickEvent event) {
secondbutton.setCaption("I am not a number!");
}
});
container.addComponent(secondbutton);
}
}
|