As mentioned above, you should not create a new instance of the type
new TicTacToe2()
So, I will continue from there. Your if statement should be something like
if (menusource == newgame) { getContentPane.removeAll(); setContentPane(aFunc); }
Create a function that looks like something below that sets the layout and adds a component to it. Put your drawing logic there and specify it as an argument to the setContent panel. for instance
private JPanel aFunc() { custSelectPanel.setLayout(null); customerTable.setDragEnabled(false); customerTable.setFillsViewportHeight(true); ...... cancelButton.setLocation(350, 0); cancelButton.setSize(100, 40); buttonPanel.add(cancelButton); return custSelectPanel; }
Hope you get the logic here.
source share