Well, I have several JFrames I put them in different classes. with a JFrame which is the used as a start frame which present a list of buttons Each one can start a frame. If I call the frame using only frame.setVisible (true). I have the frame on top of the first. I want to know how to open the second and I close the first, if you have an example I will be grateful
1 Answer
If you really want to have many frames, you can do this:
Firstly, do not launch all of the frames at once, launch only the one which contains the buttons. If a corresponding button is clicked, the start method (the one which will launch the frame) of the corresponding frame should be called. In the frame with the buttons call
this.dispose();
to stop all of the frame's actions (including visibility and presence of icons in the task bar).
Here is an example:
private void ButtonActionPerformed(){ this.dispose(); OtherFrameClass.createWindow(); } Just to clarify in this example the method is the method that is called when the button is pressed and the createWindow() method is the one that launches the next window
This will work but is not an elegant answer. Refer to The Use of Multiple JFrames, Good/Bad Practice?.
frame2.setVisible(true); frame1.setVisible(false);