Hi everyone. I am currently working on a game - Sokoban. I ran into a bit of an issue, where I want the frame to automatically resize itself when a new level begins (as most levels are different in size).
I can't seem to get it to work.
Here are parts of my code:
The game is essentially a JPanel that I draw inside a JFrame.
As you can see, I've been trying to revalidate the JFrame in different parts, but it doesn't appear to be working. I think it's revalidating the JPanel. How can I revalidate the JFrame to match the new coordinates of the JPanel?
You should instantiate your frame from within another class, not the panel class. That's a very bad approach. In this case, revalidate() refers to panel.
Did you try to invoke pack() on your frame after you change/add new panel? That should resize it to fit its content.
The quieter you are, the more you are able to hear.
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
1
have you tried calling
f.pack();
when new level starts?
(will need class level 'f')
Vas Nesterov
Greenhorn
Joined: Dec 11, 2012
Posts: 2
posted
0
Great! Calling pack() at level starts worked. I had to make my JFrame class level as well as static.
I removed revalidate from my code.