How to close a jframe without closing the main program

后端 未结 9 1842
天涯浪人
天涯浪人 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:32

    If you just hide the program, using HIDE_ON_CLOSE or set.Visible(false), that is not a very good choice, because if you do something larger with more frames, the hidden frames will still be running, slowing down computer performance. The way, as other have said, is instead of using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);, which will terminate the program when you click "X, closing all of the frames, use the following:

    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    

提交回复
热议问题