Java swing application, close one window and open another when button is clicked

前端 未结 7 1962
离开以前
离开以前 2020-12-03 07:56

I have a netbeans Java application that should display a JFrame (class StartUpWindow extends JFrame) with some options when the application is launched, then the user clicks

7条回答
  •  盖世英雄少女心
    2020-12-03 08:24

    Call below method just after calling the method for opening new window, this will close the current window.

    private void close(){
        WindowEvent windowEventClosing = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
        Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(windowEventClosing);
    }
    

    Also in properties of JFrame, make sure defaultCloseOperation is set as DISPOSE.

提交回复
热议问题