I'm creating program which has JFrame, welcome state JPanel, and game JPanel. This is short method, that switch JPanels in JFrame, from welcomeState JPanel, to game JPanel.
public static void startGameState(){
if (!Preferences.gameView) return;
/*
* Remove menu state, and set game state
*/
gameState = new GameBoard();
frame.setContentPane(gameState);
frame.invalidate();
frame.validate();
/*
* Run Server Connection Thread
*/
connectionHandler.start();
/*
* Run Game engine
* and go to Game view
*/
gameState.start();
}
Everything works fine. My Problem starts here. I have changed GameBoard class. It is no longer extending JPanel class. Now it is extending Canvas. My question is - how to remove first JPanel, and add Canvas GameBoard class instead when Im switching program states?