Can't figure out how to use JFrame's add() method right
I'm trying to make a game with multiple levels, but once I load the second level I can't move my character on screen. I know where the problem is, but I don't fully know what's going on or how to fix the problem.
The problem is adding the classes "Inner" and "Inner2" to the JFrame. I can add the variable "inner" to the JFrame easily enough by putting it at the beginning of the constructor right after the call for super(); but if I put it anywhere else I am not able to move in my game.
Everything was working just fine until I needed more than one level, so I added the Swing timer to constantly check for when the player went over a certain limit, where the game was then supposed to remove the first level from the JFrame and then add the second level.
I tried this and I found myself not able to move in the game.
public class ProjectWindow extends JFrame implements ActionListener
public Inner inner;
public Inner2 inner2;
public boolean level1;
public Timer timer;
private int check = 0;
private boolean level1unf = true;
inner = new Inner();
add(inner); // If I put this anywhere else, I can't move in the game
setTitle("Civil War Game");
level1 = true;
// if I were to put add(inner); here, it would not let me move in game.
timer = new Timer(100, this);
public void Level()
level1 = false;
public void actionPerformed(ActionEvent e)
check = inner.getInt();
if(check > 1500 && level1unf)
level1unf = false;
inner2 = new Inner2();
add(inner2); // this is where the issue is. Because I can't add
//everything in the constructor, I have to add the second level here.
// The game will basically freeze and I won't be able to move.