How to close a jframe without closing the main program

后端 未结 9 1866
天涯浪人
天涯浪人 2020-12-06 11:06

I\'m creating a program to keep track of a list of DVD\'s. On the main page I have set up 2 JButtons. When the user clicks the one that says new, a new JFrame from another c

9条回答
  •  无人及你
    2020-12-06 11:20

    Did you read the API to find out other values for the setDefaultCloseOperation(...) method?

    You can use:

    DISPOSE_ON_CLOSE - the frame will close. If this is the last open frame for the application then the JVM will terminate as well

    HIDE_ON_CLOSE - the frame is just set to invisible.

    when user clicks the one that says new a new jframe from another class comes up with fields to enter information about a new dvd.

    The real problem with your program is that you are using a frame as the popup window. You should be using a modal JDialog. An application should only ever have a single JFrame with multiple dialogs to gather additional information. A JDialog does not allow you to use EXIT_ON_CLOSE.

提交回复
热议问题