I have two JFrames opened simultaneously (by clicking certain button in the main Frame I open second Frame). I can of course exit whole program by clicking X on the main frame. The thing is: is there a way to close my subFrame by clicking X while the Main Frame remain opened? In the subFrame there is going certain action and I want to shut it down by click X but not closing the Main Frame at a time.
Write your close function like this
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)
Related
I have 3 Jframe, when I click on first Jframe, it closes it and opens new, is there any way to call second jframe on this window?
I am trying to make a game menu where if you click a button it goes onto another window (which I made in another class). With my current code, the window does not close, rather it goes invisible.
I have tried using System.exit(0); and dispose();. However, System.exit(0) does not open the other window and dispose(); does not completely exit the window.
In the actionPerformed method right now I use
Class.main(new String[0]); to open the new class and I use setVisible(false); to close the current class. But this does not accomplish what I want.
The output I expect is when you click one of the JButton's it completely closes the PongGUI class and opens the corresponding class.
I'm making a simple arithmetic game.
The first frame is a login screen, next this will close and then open a new frame after the user is logged in.
In the next frame, you can choose buttons which represent the game's modes and when I click a button a new frame opens.
What I am trying to accomplish is that I want is to continue working within this new frame. I don't want to keep moving between frames.
I am trying to make a back button for each mode so I can return to the original modes frame. I am only using the two frames for my program.
Is there a way I can choose the mode then go to a new screen and still be able to go back to the mode selection frame?
You could have 2 JPanels and when you press a button, an action listener does
Frame.remove(Panel1);
Frame.add(Panel2);
When my program launches, a window (aka "StartWindow") opens that has 3 options: New Game/Load Game/Exit. When New Game or Load Game is clicked (and after some input), the game window (aka "GameWindow") will open so the user can play.
When the GameWindow opens, I would like to have the StartWindow close. And when the GameWindow closes, the StartWindow will open until the actual "EXIT" button is clicked.
Is there a way to do this? Right now, the only way I can achieve something similar to this is having a boolean called "gameRunning". When this is true, the buttons on StartWindow will have no action when clicked. Opposite when false.
For example purposes, suppose that each window has 3 buttons, a text field, and nothing else.
Use setVisible(false) method on parent before opening any child window. When child window closes call setVisible(true). It will solve your problem
If I have two JFrames where one is the main JFrame, and the other one pops up when I click something. Now what I want is that when the new frame pops up, the main one should be minimized. Also when I click on this popup frame to close it, the main should be restored back.
Essentially I want to know, how can we maximize and minimize a JFrame apart from the default click operation. Is there any function for doing this on custom click for example?
1) setDefaultCloseOperation to NOTHING_ON_CLOSE
2) addWindowListener to JFrame
3) overrive windowsClosing() method with proper Action for iconify ...
4) don't forget to set to the JMenuItem/JButton System.exit(1), because in this form current JVM instence never gone from PC RAM or swap area until PC restarted or switch off
5) better would be to change 2nd. JFrame to the JDialog because in most cases is too hard manage lots of methods betweens two JFrames
setPatent
setModal
setModalityTypes