如何在继续之前等待JFrame关闭? [英] How to wait for a JFrame to close before continuing?

查看:128
本文介绍了如何在继续之前等待JFrame关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序包含3个主要部分。主要功能,登录表格和App表格。主要功能应该是这样的:打开登录表单,等待它关闭,然后打开App表单。我不能让等待的部分工作,或者更确切地说,我不知道如何去做。

My program consists of 3 main 'sections'. Main function, Login form and App form. The main function should do something like: Open Login form, wait for it to close, then open App form. I can't get the waiting part to work, or rather, I don't know how I would go around doing that.

有人告诉我使用了改为使用JDialog并使用 setModal(true),但是使用这种方法,登录表单不会出现在任务栏上,这在我看来很糟糕。

I was told by someone to use a JDialog instead and use setModal(true), but with that approach the Login form wouldn't appear on the taskbar, which is terrible in my opinion.

我考虑的另一件事是在关闭后从Login内部打开应用程序,但这感觉就像糟糕的设计,因为这会使登录表单不可重用。

Another thing I considered was to open the App from inside the Login after it closes, but that feels like bad design since that'd make the Login form non-reusable.

那么,请问,你会建议什么?

So, please, what would you suggest?

推荐答案


  • 为什么登录必须出现在任务栏上,因为主应用程序将在那里,并且您不希望单个程序有多个任务栏项。您最好的选择可能是使用模态JDialog。

  • 另一种选择是使用 CardLayout 交换视图。

  • 第三个选项是使用JFrame,如果你必须附加一个监听器,我相信一个WindowListener,回应它的近距离事件。

  • 无论你去哪条路线,你的登录gui应该是一个JPanel,这样你就可以把它放在任何你想去的地方,然后改变主意。

    • Why must the login appear on the task bar, since the main app will be there, and you don't want more than one task bar item for an individual program. Your best option may be to use a modal JDialog.
    • Another option is to use CardLayout to swap "views".
    • A third option is to use a JFrame if you must but attach a listener to it, a WindowListener I believe, to respond to its close event.
    • Regardless of which route you go, your login gui should be a JPanel so that you can place it anywhere you wish and then change your mind later.
    • 这篇关于如何在继续之前等待JFrame关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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