Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Title says it all, before anyone says that there is a thread about closing a GUI without the program end then hold on a second.

My question is that, how can the PROGRAM close a GUI and not the user so it can progress onto another frame.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
146 views
Welcome To Ask or Share your Answers For Others

1 Answer

If this question below is about a Swing GUI:

My question is that, how can the PROGRAM close a GUI and not the user so it can progress onto another frame.

Then this question can be answered thusly:

  • Set the JFrames default close operation property to JFrame.DO_NOTHING_ON_CLOSE.
  • A program can close any window by calling close() or setVisible(false) on the window.

i.e.,

myJFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

But having said that, the question in fact should be answered:

  • Don't do this as this is a bad program design. No user wants windows flung at him.
  • Instead have one main JFrame window open and rather than open and close windows, change views in the window by swapping JPanels, each holding its own simple or complex GUI.
  • A CardLayout can help you do this easily.

Again, note that your question as originally stated is very incomplete, and in the future, you will want to tell us any and all relevant libraries that are involved, here the Swing library since the question is likely essentially a Swing question. You will also want to show some code and explain exactly where you might be stuck. Usually the better the question, the better the answers you'll see. For instance, with more information and code, we could show you some code to get you started with a CardLayout.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...