简体   繁体   中英

Need to close a jframe while showing another one

I am building a desktop student management app in 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 ). 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? 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM