title: Drawing a game board in java
body: <p>I am referencing this link, however this won't ultimately fix my problem (i.e I run my program from someone else's computer). <a href="https://stackoverflow.com/questions/37335/how-to-deal-with-java-lang-outofmemoryerror-java-heap-space-error-64mb-heap">How to deal with &quot;java.lang.OutOfMemoryError: Java heap space&quot; error (64MB heap size)</a>. Right now, I have a game board that has 10x10 squares, but I need to increase this to 100x100, but when I do, I get this error. What is the best way to increase my game board size while avoiding this error? Current output is below, Code should compile and run. Thanks!</p>
  
  <p><a href="https://i.stack.imgur.com/f1v5M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f1v5M.png" alt="enter image description here"></a></p>
  
  <p>GameBoard Class:</p>
  
  <pre><code>import java.awt.*;
  import java.awt.image.BufferedImage;
  import javax.swing.*;
  import javax.swing.border.*;
  
  public class GameBoard {
  
  private final JPanel board = new JPanel(new BorderLayout(3, 3));
  private JButton[][] c1squares = new JButton[10][10];
  private JPanel c1Board, c2Board;
  private final JLabel messagec1 = new JLabel("Player 1 Board");
  JToolBar tool = new JToolBar();
  Insets Margin = new Insets(0,0,0,0);
  int squares = 10;
  int space = 100;
  ImageIcon icon = new ImageIcon(new BufferedImage(space, space, BufferedImage.TYPE_INT_ARGB));
  
  GameBoard() {
      initializeGui();
  }
  
  public final void initializeGui() {
  
      board.setBorder(new EmptyBorder(5, 5, 5, 5));
      tool.setFloatable(false);
      board.add(tool, BorderLayout.PAGE_START);
      tool.add(messagec1);
      c1Board = new JPanel(new GridLayout(0, 10));
      c1Board.setBorder(new LineBorder(Color.BLACK));
      board.add(c1Board);
  
      for (int i = 1; i &lt; c1squares.length; i++) {
          for (int j = 0; j &lt; c1squares[i].length; j++) {
              JButton b = new JButton();
              b.setMargin(Margin);              
              b.setIcon(icon);
              if ((j % 2 == 1 &amp;&amp; i % 2 == 1) || (j % 2 == 0 &amp;&amp; i % 2 == 0)) {
                  b.setBackground(Color.WHITE);
              } else {
                  b.setBackground(Color.BLACK);
              }
              c1squares[j][i] = b;
          }
      } 
      for (int i = 1; i &lt; squares; i++) {
          for (int j = 0; j &lt; squares; j++) {     
                      c1Board.add(c1squares[j][i]);      
          }
      } 
  public final JComponent getGui() {
      return board;
  }
  public final JComponent getGui2() {
      return board2;
  }
  }
  </code></pre>
  
  <p>BattleShipFinal Class:</p>
  
  <pre><code>import java.awt.Dimension;
  import java.awt.Toolkit;
  import javax.swing.JFrame;
  
  public class BattleshipFinal {
  
  public static void main(String[] args) {
  
      GameBoard gb = new GameBoard();
      JFrame frame = new JFrame("Battleship - Server");
      frame.add(gb.getGui());
      frame.setLocationByPlatform(true);
      frame.setMinimumSize(frame.getSize());
      frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
      frame.setPreferredSize(new Dimension(900,900));
      frame.setMinimumSize(new Dimension(900,900));
      frame.setLocation(50,50);
      frame.pack();
      frame.setVisible(true);
  
  }
  
  }
  </code></pre>