Hi

I have written a sample code which it’s got a button. when i click on the button i expect to see the new window(form) opens. but nothing happens.where is the problem?(i have done it with swing and it works)
thank you in advance.
here is the code:

public class TestvaadinApplication extends Application {

Button btnADD = new Button(“ADD”);
Button.ClickListener btnListener =
new MyBtnListener();

btnADD.addListener(btnListener);
}

public class MyBtnListener extends Application implements Button.ClickListener {

public void buttonClick(ClickEvent event) {
	// TODO Auto-generated method stub
	Window main = new Window("Book Succesfully added");
	
	Label lblSuccess = new Label("The bood Added!");
	main.addComponent(lblSuccess);
	setMainWindow(main);
}

@Override
public void init() {
	// TODO Auto-generated method stub
	
}

}

Hi,
In the sample code you show, your button listener class, MyBtnListener, extends Application class. While you may think it’s okay, it indeed causes problem since you have another class for your application.

You have some options to fix this:

  1. let the application class implement Button.ClickListener and set the application itself as the listener to button click
    drawback: not scalable, if you have several buttons in the application you should create a switch to detect which button raises the event

public class TestvaadinApplication extends Application implements Button.ClickListener {
...
    Button btnAdd = new Button("ADD");
    btnAdd.addListener(this);

    public void buttonClick (ClickEvent event) {
         //Write the button click handler here
    }
..
}
  1. create an anonymous button listener class instance for the button

public class TestvaadinApplicaton extends Application {
...
    Button btnAdd = new Button("ADD");
    btnAdd.addListener(new ClickListener {
        public void buttonClick (ClickEvent event) {
            //Write the button click handler here
        }
     });
...
}
  1. create a private class as the button listener class for the button and assign an instance of the class as a listener of the button

public class TestvaadinApplication extends Application {
...
    Button btnAdd = new Button("ADD");
    btnAdd.addListener(new MyButtonClickListener());
...
    private class MyButtonClickListener implements Button.ClickListener {
        public void buttonClick (ClickEvent event) {
            //Write the button click handler here
        }
    }
...
}

Dear Mikael Fernandus,
Hi,
Thank you.
I really apprecited.