title: Creating a Wheel of Fortune-esque puzzle board using JPanel/JFrame Java
body: <p>I was assigned a free-form Java coding assignment in my computer science class in which my group and I decided to make a Wheel of Fortune type game. I've been working on the GUI using <code>JPanel</code>and <code>JFrame</code>, which our online academy goes into some detail on, so I know most of the absolute basics. I managed to get a non-aesthetic but functioning box that displays individual player money and name in a class named <code>playerPlate</code>, as well as a button panel for all the buttons we will need at some point during the game in a class called <code>buttonPanel</code>. </p>
  
  <p>When it came to making the letter/puzzle board where the puzzle is displayed on a 12-14-14-12 grid, I experienced a slew of problems. Here is my code for the <code>letterBoard</code> class which I'm using to try to make the puzzle board.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  import javax.swing.*;
  
  public class letterBoard extends JPanel
                              implements ActionListener                   
  {
  private JTextField a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,
  a11,a12,a13,a14,a15,a16,a17,a18,a19,a20,a21,a22,a23,
  a24,a25,a26,a27,a28,a29,a30,a31,a32,a33,a34,a35,a36,
  a37,a38,a39,a40,a41,a42,a43,a44,a45,a46,a47,a48,a49,
  a50,a51,a52;
      JTextField board[] = new JTextField[52];
      public letterBoard()
      {
      setBackground(Color.GREEN);
      JTextField a1 = new JTextField(" ");
      JTextField a2 = new JTextField(" ");
      JTextField a3 = new JTextField(" ");
      JTextField a4 = new JTextField(" ");
      JTextField a5 = new JTextField(" ");
      JTextField a6 = new JTextField(" ");
      JTextField a7 = new JTextField(" ");
      JTextField a8 = new JTextField(" ");
      JTextField a9 = new JTextField(" ");
      JTextField a10 = new JTextField(" ");
      JTextField a11 = new JTextField(" ");
      JTextField a12 = new JTextField(" ");
      JTextField a13 = new JTextField(" ");
      JTextField a14 = new JTextField(" ");
      JTextField a15 = new JTextField(" ");
      JTextField a16 = new JTextField(" ");
      JTextField a17 = new JTextField(" ");
      JTextField a18 = new JTextField(" ");
      JTextField a19 = new JTextField(" ");
      JTextField a20 = new JTextField(" ");
      JTextField a21 = new JTextField(" ");
      JTextField a22 = new JTextField(" ");
      JTextField a23 = new JTextField(" ");
      JTextField a24 = new JTextField(" ");
      JTextField a25 = new JTextField(" ");
      JTextField a26 = new JTextField(" ");
      JTextField a27 = new JTextField(" ");
      JTextField a28 = new JTextField(" ");
      JTextField a29 = new JTextField(" ");
      JTextField a30 = new JTextField(" ");
      JTextField a31 = new JTextField(" ");
      JTextField a32 = new JTextField(" ");
      JTextField a33 = new JTextField(" ");
      JTextField a34 = new JTextField(" ");
      JTextField a35 = new JTextField(" ");
      JTextField a36 = new JTextField(" ");
      JTextField a37 = new JTextField(" ");
      JTextField a38 = new JTextField(" ");
      JTextField a39 = new JTextField(" ");
      JTextField a40 = new JTextField(" ");
      JTextField a41 = new JTextField(" ");
      JTextField a42 = new JTextField(" ");
      JTextField a43 = new JTextField(" ");
      JTextField a44 = new JTextField(" ");
      JTextField a45 = new JTextField(" ");
      JTextField a46 = new JTextField(" ");
      JTextField a47 = new JTextField(" ");
      JTextField a48 = new JTextField(" ");
      JTextField a49 = new JTextField(" ");
      JTextField a50 = new JTextField(" ");
      JTextField a51 = new JTextField(" ");
      JTextField a52 = new JTextField(" ");   
      Box b1 = Box.createHorizontalBox();
      b1.add(Box.createHorizontalGlue());
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a1);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a2);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a3);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a4);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a5);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a6);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a7);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a8);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a9);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a10);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a11);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(a12);
      b1.add(Box.createHorizontalStrut(5));
      b1.add(Box.createHorizontalGlue());
      Box b2 = Box.createHorizontalBox();
      b2.add(Box.createVerticalStrut(5));
      b2.add(a13);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a14);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a15);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a16);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a17);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a18);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a19);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a20);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a21);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a22);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a23);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a24);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a25);
      b2.add(Box.createVerticalStrut(5));
      b2.add(a26);
      b2.add(Box.createVerticalStrut(5));
      Box b3 = Box.createHorizontalBox();
      b3.add(Box.createVerticalStrut(5));
      b3.add(a27);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a28);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a29);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a30);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a31);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a32);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a33);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a34);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a35);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a36);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a37);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a38);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a39);
      b3.add(Box.createVerticalStrut(5));
      b3.add(a40);
      b3.add(Box.createVerticalStrut(5));
      Box b4 = Box.createHorizontalBox();
      b4.add(Box.createVerticalStrut(5));
      b4.add(a41);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a42);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a43);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a44);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a45);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a46);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a47);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a48);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a49);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a50);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a51);
      b4.add(Box.createVerticalStrut(5));
      b4.add(a52);
      b4.add(Box.createVerticalStrut(5));
      add(b1);
      add(b2);
      add(b3);
      add(b4);    
      }
      public void actionPerformed(ActionEvent e) 
      {
      //logic to be added later
      }
     }
  </code></pre>
  
  <p>Sorry about the sloppy code. First time posting and was having a bit pf trouble getting it to format correctly. When the above code is run through the <code>wheelGUI</code> class, it essentially creates 4 separate horizontal segments that are much smaller than I would like, editable, and not stacking correctly. I played around with different boxes, struts, and border layouts but could never get it to work properly. And while the code does compile and run (I'm aware of some consistency errors between the separate boxes, forgot to re-do that segment) it is extremely inefficient, as any changes must be done to ~52 different lines of code. I experimented with an <code>iterate</code> method I made:</p>
  
  <pre><code>public void iterate(JTextField[] foo)
  {
      board = foo;
      for(int i=0; i&lt;foo.length; i++)
      {
          foo[i] = new JTextField(" ");
      }
  }
  </code></pre>
  
  <p>However, this resulted in a <code>NullPointerException</code> error and did not properly instantiate the a1-52 variables to be used in the boxes. Any help I could get would be great. I apologize if my post and my code are a mess.</p>