简体   繁体   中英

Closing JDialog Java

How can I stop dialog box running?

String menuInput = null;
        JOptionPane askOpenOrNew = new JOptionPane(
                "Would you like to Open a save\nor create a New world?");
        Object[] askOptions = new String[] { "Open World", "New World",
                "Cancel" };
        askOpenOrNew.setOptions(askOptions);
        JDialog askDialog = askOpenOrNew.createDialog(new JFrame(),
                "There is no World");
        askDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        askDialog.setVisible(true);

It keeps the console in Eclipse running after the program, should have, terminated.

EDIT: The dialog box does close (In that it disappears from screen) but the console doesn't terminate unless explicitly told (System.exit(0)).

如果要退出程序,建议您显式调用System.exit(0)

If you want the program to exit after you close the dialog box, you replace

askDialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

With

askDialog.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

I hope this is what you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM