visual designer and events handling

I’ve been trying the visual designer.
And I wonder how can I handle event I’ve been trying without success to put code such as :

		ButtonSave.addListener(new Button.ClickListener() {
		    public void buttonClick(ClickEvent event) {
		        ButtonSave.setCaption("You pushed it!");

Shall I create a new class that heritate from the component and implements «Button.ClickListener» ?