Fill Board with Tiles and Use Font Metrics

Creating the board panel

Now that you can create a bag of letters to hold all the letters, add code to WordBuilder to display all the tiles, side by side.

First, create the board to hold the tiles and the board panel that will display the board.

  1. In WordBuilder class, add private static final integer instance variables called ROWS, COLS, and MAX, set to 8, 12, and 15, respectively.
  2. Add a private LetterPanel two-dimensional array instance variable called board, with ROWS rows and COLS columns.
  3. Add a private JPanel instance variable called boardPanel, initialized by calling JPanel’s constructor.
  ...
 
public class WordBuilder extends JFrame {
  private static final long serialVersionUID = 1L;
  _______________ ROWS = ______;
  _______________ COLS = ______;
  _______________ MAX = ______;
  
  _______________ board = ___________________;
 
  private JPanel mainPanel = new JPanel();
  ____________ boardPanel = ______________;
 
    ...

Get hands-on with 1200+ tech skills courses.