I have a quick question regarding JFrames and disposing them properly. I have a game that has multiple levels, I wish to dispose of the frame in use when another is created with a new level.
The program I am currently working on extends a JFrame which has always confused me as I don't know what that JFrame is called.
Anyway, I have another class that extends a JPanel. In this class I have a method that, when the game state is completed, removes all instances and closes the JFrame. Yet this does not work because I cannot get the frame of the frame, instead I get multiple instances of the same JFrame.
So my set up looks like this:
Class 1 extends JFrame .... .... ....
Class 2 extends JPanel ... ... method(clears everything + gets new JFrame for new level) ...
Sorry if that is vague, I don't want to post hundreds of lines of code for a short question. I know others have asked this question but I can never seem to get it to work for me.
So once again, my question is simply how do you close a JFrame in another class method.
(Please note everything works perfectly, I just can't close the frame without it breaking completely on me)