public void actionPerformed(ActionEvent e) {
    boolean[][] cells = cells1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        cells2[i][j] = cells[i][j];
        int nb = neighbors(cells, i, j);
        if (nb == 3)
          cells2[i][j] = true;
        if (nb < 2 || nb > 3)
          cells2[i][j] = false;
      }
    }
    
    cells1 = cells2;
    cells2 = cells;
    repaint();
  }