[英]Need to close a jframe while showing another one
I am building a desktop student management app in java. 我正在用Java构建桌面学生管理应用程序。 So I need to close the current JFRAME while an another JFRAME is visible(after closing the new jframe old jframe should be visible ). 因此,我需要在另一个JFRAME可见的同时关闭当前JFRAME(在关闭新的jframe之后,旧的jframe应该可见)。 Could you please help me ? 请你帮助我好吗 ?
Your basic idea is generally not recommended. 通常不建议您使用基本概念。 You can have a look at The Use of Multiple JFrames: Good or Bad Practice? 您可以看看“使用多个JFrame:好做法还是坏做法”? for the long winded discussion. 进行长时间的讨论。
Generally it's recommended to use a CardLayout
for these type of operations, see How to use CardLayout for more details 一般来说,建议使用一个CardLayout
对于这些类型的操作,请参阅如何使用CardLayout了解更多详情
What you want to try and do is decouple of the navigation decision making from the views themselves - there's no reason why the first and second view should ever care about each other OR be backing decisions about how the user should navigate. 您想要尝试做的是将导航决策与视图本身脱钩-没有理由为什么第一个视图和第二个视图应该彼此关心,或者支持有关用户应如何导航的决策。
您可以使用JFrame#dispose仅关闭一帧,这当然需要引用您要处置的JFrame
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.