Java:如何在打开另一个JFrame的同时关闭它? [英] Java: How do I close a JFrame while opening another one?

查看:64
本文介绍了Java:如何在打开另一个JFrame的同时关闭它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序从JFrame中带有文本字段的图片开始.我想要在用户类型启动时关闭图片JFrame并使用主程序打开另一个JFrame.我已经尝试过

My program starts with a picture with a textfield in a JFrame. I want when the user types start it closes the picture JFrame and opens another JFrame with the main program. I've tried

processEvent(新的WindowEvent(this,WindowEvent.WINDOW_CLOSING));

在图像框架上,但是它关闭了所有窗口.

on the Image frame but it closes all the windows.

推荐答案

方法 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.

这篇关于Java:如何在打开另一个JFrame的同时关闭它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆