2

i have design two JFrames in netbeans(new-> Jframe ) and add one botton on each jframe , when i click a button from frame1 it opens Jframe2 its okay but i want is that the JFrame1 should be closed or not appear on the window..and alternatively when i click button from jframe2 it opens jframe1 but jframe2 should be closed..the one thing i achieved is jframes are opening on buttons click but jframes are not closing as per my requirements.. so i need expertise from you guys to fix this problem.

4

1 回答 1

3

在您的按钮事件处理程序中(假设您的类 extends JFrame),在打开新框架之前执行以下操作:this.dispose()

从Java doc,.dispose()方法:

公共无效处置()

释放此 Window、其子组件及其所有子组件使用的所有本机屏幕资源。也就是说,这些组件的资源将被销毁,它们消耗的任何内存都将返回给操作系统,并且它们将被标记为不可显示。

通过随后调用 pack 或 show 重建本机资源,可以使 Window 及其子组件再次可显示。重新创建的 Window 及其子组件的状态将与这些对象在 Window 被释放时的状态相同(不考虑这些操作之间的其他修改)。

于 2013-09-23T08:39:51.313 回答