i have a Jframe which has some panels as instance variables and one of the panels is a grid board (i am implementing Lines of action game). After my game ends I have a button "Play again" which i want to reinitialize my board panel. I tried a lot of things like removing my panel from the content pane and re-initializing it, but nothing worked so far. Here are some of the things i tried (i didn't try them all at once )
public class Frame extends JFrame implements  MouseListener{
JLabel l = new JLabel();
Panel1 Boards;
Panel2 newGame;
Panel3 winner;
Point lastCheckerSelected;
Board game = new Board();
    public Frame() {
    setResizable(false);
    setTitle("Lines Of Action");
    setBounds(290, 350, 1000, 700);
    setLayout(null);
   winner=new Panel3(); 
    winner.playAgain.addMouseListener(this);
    getContentPane().add(winner);
    Boards= new Panel1();
     getContentPane().add(Boards);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    l.setIcon(new ImageIcon(
            "E:\\background0213.jpg"));
    l.setBounds(0 ,0 ,  1000 , 700);
    getContentPane().add(l);
    validate(); 
    newGame=new Panel2();
    newGame.b.addMouseListener(this);
  getContentPane().add(newGame);
  for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
          Boards.x[i][j].addMouseListener(this);
          Boards.y[i][j].addMouseListener(this);
      }
  }
}
 public void mouseClicked(MouseEvent e) {
    if(e.getSource().equals(newGame.b)) {
           Boards.setVisible(true);
           newGame.setVisible(false);
           game=new Board();
     }
if(this.game.getWinner()==1) {
    winner.setVisible(true);
    winner.whiteWins.setVisible(true);
}
if(this.game.getWinner()==2) {
    winner.setVisible(true);
    winner.greywins.setVisible(true);
}
if(e.getSource().equals(winner.playAgain)) {
            //this.getContentPane().remove(Boards);
        //  this.game= new Board();                                          
        //  Boards = new Panel1();      
        //  this.getContentPane().add(Boards);
            //Boards.setVisible(true);
        //  validate();
        //  Boards.repaint();
        }
}
public static void main(String[] args) {
    Frame frame = new Frame();
    frame.setVisible(true);
}
I still cant make my new panel appear ( removing the Boards panel from the content pane makes it disappear which is good but the new one does not appear) here is my panel =1 that contains the board
public class Panel1 extends JPanel  {
JButton[][] x = new JButton[8][8];
JButton[][] y=new JButton[8][8];
Graphics g;
public Panel1() {
    setBounds(0, 30 ,400 ,400); 
    setLayout(new GridLayout(8, 8));
    setOpaque(false);
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
            x[i][j] = new JButton();
            x[i][j].setSize(50, 50);
            if ((i % 2 == 0 && j % 2 == 0) || (i % 2 != 0 && j % 2 != 0)) {
                x[i][j].setBackground(Color.DARK_GRAY.darker());
            //  x[i][j].setBackground(new Color(111,89,81,150));
            }
            else {
                // Color.OPAQUE = 2;
                x[i][j].setBackground(Color.red.darker().darker());
            //  x[i][j].setBackground(new Color(223,37,32,150));
            }
            x[i][j].setEnabled(false);
            add(x[i][j]);
        }
    }
for(int i = 0; i < 8 ;i++){
    for(int j=0;j < 8;j++){
        y[i][j]=new JButton();
    x[i][j].add(y[i][j]);   
    //  y[i][j].setSize(100,100);
    //  y[i][j].setEnabled(false);
    //  y[i][j].setOpaque(false);
    //  y[i][j].setContentAreaFilled(false);
//      y[i][j].setBorderPainted(false);
        y[i][j].setVisible(false);
    }
}
for(int i=1;i<7;i++){
//  y[0][i].setOpaque(true);
    y[0][i].setBackground(Color.white);
    y[0][i].setEnabled(true);
    y[0][i].setVisible(true);
//  y[7][i].setOpaque(true);
    y[7][i].setBackground(Color.white);
    y[7][i].setEnabled(true);
    y[7][i].setVisible(true);
}
for(int i=1;i<7;i++){
//  y[i][0].setOpaque(true);
    y[i][0].setEnabled(true);
    y[i][0].setBackground(new Color(102,125,153));
    y[i][0].setVisible(true);
//  y[i][7].setOpaque(true);
    y[i][7].setEnabled(true);
    y[i][7].setBackground(new Color(102,125,153));
    y[i][7].setVisible(true);
}
//  addMouseListener(this);
    setVisible(false);
}
}