problem with adding listener to a window

hey,
i am trying to add a listener to a window, so whenever there is a view change, the window will close.
i tried this:

    private class LoginWindow extends Window{
    
        LoginWindow() {
        setClosable(true);
        setResizable(false);
        setDraggable(false);
        setSizeUndefined();
        addListener(new ViewChangeListener(){

            @Override
            public boolean beforeViewChange(ViewChangeEvent event) {
                // TODO Auto-generated method stub
                return false;
            }

            @Override
            public void afterViewChange(ViewChangeEvent event) {
                // TODO Auto-generated method stub
                
            }
            
        });

but i get this error: The method addListener(Window.CloseListener) in the type Window is not applicable for the arguments (new ViewChangeListener(){}).

how can i add a listener which is not a close listener to this window?

Thanks

Well you can’t. Window does not support this Listener. It will also never throw a ViewChangeEvent. The only object which can throw a ViewChangeEvent and to which you can add a ViewChangeListener is Navigator.
To close the window on ViewChange you should add the Listener to your Navigator and then reference the window and call window.close() on viewChange.