Nipuna C
Nipuna C

Reputation: 81

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 ?

Upvotes: 0

Views: 59

Answers (2)

MadProgrammer
MadProgrammer

Reputation: 347184

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.

Upvotes: 1

Dinh
Dinh

Reputation: 779

You can use JFrame#dispose to close just one frame, this ofcourse requires a reference to the JFrame you want to dispose

Upvotes: 0

Related Questions