且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java:如何在打开另一个JFrame的同时关闭它?

更新时间:2023-01-07 18:17:31

方法 JFrame.setVisible 可用于基于参数隐藏或显示JFrame,而 JFrame.dispose实际上会通过关闭框架并释放其使用的资源来破坏"框架.在这里,如果要重新打开图片,请在相框上调用 setVisible(false),如果不想打开,请在相框上调用 dispose()再次,这样您的程序就可以释放一些内存.然后,您将在主框架上调用 setVisible(true)使其可见.

The method JFrame.setVisible can be used to hide or display the JFrame based on the arguments, while JFrame.dispose will actually "destroy" the frame, by closing it and freeing up resources that it used. Here, you would call setVisible(false) on the picture frame if you intend to reopen it, or call dispose() on the picture frame if you will not be opening it again, so your program can free some memory. Then you would call setVisible(true) on the main frame to make it visible.