0

I have three frames, let's call them Frame Welcome, Frame Main, Frame Sub. They're all in separate classes.

Frame Welcome has a button that makes Frame Main visible when clicked.

Frame Main has a button that makes Sub pop up when clicked (sort of a dialog box yeah but it has graphical design so I figured out to just put it in a separate frame, though I'm considering JPanel but I'm not sure how to do that: how to make it pop up when it's in a JPanel, possibly setVisible but I havent tried that yet so I might try it later), but there is also a button in Frame Sub which when clicked, should make Frame Main and Frame Sub invisible and display Frame Welcome only instead.

At the moment, I have a code for making Sub disappear and make Welcome appear, but I can't figure out how to make Main invisible too.

public void actionPerformed (ActionEvent e)
{
if (e.getSource() == btn)
{
FrameWelcome fw = new FrameWelcome();
setVisible(false);
fw.setVisible(true);
}
}

This makes the Frame Sub invisible and the Frame Welcome visible, but how will I make Frame Main invisible too (Sub is SORT OF inside Main, because it's displayed when a button is clicked in Main)? This isn't exactly my code but I'm not sure which parts to post so yeah

user3026693
  • 133
  • 2
  • 11
  • 3
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Feb 06 '14 at 09:46
  • 2
    *"I figured out to just put it in a separate frame, though I'm considering JPanel but I'm not sure how to do that: how to make it pop up when it's in a JPanel"* Use the `JPanel`, then you're probably looking for `CardLayout` to display it in the same frame, or a `JDialog` or `JOptionPane` for a free floating display element (AKA a top-level container). – Andrew Thompson Feb 06 '14 at 09:48
  • @AndrewThompson Yeah kinda agree that the use of multiple JFrames (I've done some research) is not really good practice but I'm still trying to find my way around GUI since I only started last week but thanks for the answer and I'll give your suggestions a try – user3026693 Feb 06 '14 at 09:56
  • 2
    See this simple `CardLayout` [**example**](http://stackoverflow.com/a/21460065/2587435) – Paul Samsotha Feb 06 '14 at 10:42

0 Answers0