简体   繁体   中英

How Can A Program Close A GUI Without The Program Ending

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.

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.

ie,

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.

java.awt.Window aTopLevelGUI; // Normally referenced as a JWindow, but this is what impls setVisible(boolean)

// To close the window:
aTopLevelGUI.setVisible(false);

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