does not open a window

public class MCS extends com.vaadin.Application {

    final Window main = new Window("window name");

    @Override
    public void init () {
        this.setMainWindow(main);
        main.addComponent(new Phonebook().getPhonebook());
    }
}
public class Phonebook extends MCS {

    public VerticalLayout getPhonebook () {
        VerticalLayout vl = new VerticalLayout();
        final Window window = this.getWindow();

        Button button = new Button("Click ME");
        button.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick (ClickEvent event) {
                main.addWindow(window);
            }
        });

        vl.addComponent(button);
        return vl;
    }
    public Window getWindow () {
        Window window = new Window("Hello world!");
        return window;
    }
}

does not open a window.
Why?

Try changing main.addComponent(new Phonebook().getPhonebook()); to main.setContent(new Phonebook().getPhonebook());

Cheers,

Charles.

redid

public class MCS extends com.vaadin.Application {

    final Window main = new Window("window name");

    @Override
    public void init () {
        this.setMainWindow(main);
        Phonebook phonebook = new Phonebook();
        main.addComponent(phonebook.getPhonebook(phonebook));
    }
}
public class Phonebook extends MCS {

    public VerticalLayout getPhonebook (final Phonebook phonebook) {
        VerticalLayout vl = new VerticalLayout();


        Button button = new Button("Click ME");
        button.addListener(new Button.ClickListener() {

            @Override
            public void buttonClick (ClickEvent event) {
                main.addWindow(phonebook.getWindow());
            }
        });

        vl.addComponent(button);
        return vl;
    }
    public Window getWindow () {
        Window window = new Window("Hello world!");
        return window;
    }
}

does not work

is bug?

I don’t know why are you doing it that way, but maybe this is what you wanted to do:

public class Phonebook {
	private Window mainWindow;

	public Phonebook(Window mainWindow) {
		this.mainWindow = mainWindow;
	}

	public VerticalLayout getContent() {
		VerticalLayout vl = new VerticalLayout();

		Button button = new Button("Click ME");
		button.addListener(new Button.ClickListener() {

			@Override
			public void buttonClick(Button.ClickEvent event) {
				Phonebook.this.mainWindow.addWindow(Phonebook.this.getWindow());
			}
		});

		vl.addComponent(button);
		return vl;
	}

	public Window getWindow() {
		Window window = new Window("Hello world!");
		return window;
	}
}
public class MCS extends com.vaadin.Application {

	final Window main = new Window("window name");

	@Override
	public void init() {
		this.setMainWindow(main);
		Phonebook phonebook = new Phonebook(main);
		main.addComponent(phonebook.getContent());
	}
}