如何在不退出JVM/Application的情况下关闭并打开JFrame? [英] How to close a JFrame and open it consequently, without exit the JVM/Application?

查看:60
本文介绍了如何在不退出JVM/Application的情况下关闭并打开JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在不退出JVM/整个应用程序的情况下关闭并打开JFrame?我希望只退出并立即打开JFrame,而不关闭JFrame1或从根本上退出JVM/整个应用程序.我想用一个JButton来做.

How to close a JFrame and open it consequently, without exit the JVM/entire application? I want that only the JFrame be exited and opened immediately, without close the JFrame1 nor principally exit the JVM/entire application. I want do it with a JButton.

我想要这样的一个JButton:JButton(我关闭了这个JFrame并立即打开了它,以便再次执行构造函数,而无需退出JVM/应用程序");

I want a JButton this way: JButton("I close this JFrame and open this immediately, so that the constructor is executed again, without exit the JVM/application");

我想要但我不知道怎么做:我需要一种方法,当您单击窗口的"x"时,以相同的方式关闭JFrame窗口.将如下所示:JFrame.close(); //就像窗口的"x"一样JFrame.setVisible(true)

What I want but I don't know how to do is: I need a method that closes the JFrame window the same way when you click on the "x" of a window. Would be as follows: JFrame.close(); //like the "x" of a window JFrame.setVisible(true)

谢谢.

JFrame功能的图片在这里:

The print of JFrame functionality is here:

我找到了自己的答案

推荐答案

我用Google搜索并找到了解决方案,是这样的:

I googled and i find the solution, and is this:

       WindowEvent closingEvent = new WindowEvent(frame, WindowEvent.WINDOW_CLOSING);
       Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(closingEvent);
       frame.setVisible(true);

它使用WindowEvent进行与"x"点击相同的操作.

It uses a WindowEvent to do the same as "x" click does.

无论如何,谢谢你们的帮助!

Thank you guys anyway for your help!!!

这篇关于如何在不退出JVM/Application的情况下关闭并打开JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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