Add Tiles

Learn to add a tile to the window with text and points and set up a class for holding all the tiles.

Adding a tile to the window

Add a LetterPanel to WordBuilder so you can see what a tile looks like.

  1. Add a private JPanel instance variable called mainPanel, initialized by calling JPanel’s constructor.
  2. In the main panel section of initGUI(), add mainPanel to the center of the window. Use JFrame’s add() method and BorderLayout’s CENTER variable.
  3. Create a new LetterPanel object called letterPanel, with the letter “A” and 1 point, and add letterPanel to mainPanel using JPanel’s add() method.
    ...
 
public class WordBuilder extends JFrame {
  private static final long serialVersionUID = 1L;
  
  ____________ mainPanel = ______________;
 
    ...
 
  private void initGUI() {
    TitleLabel titleLabel = new TitleLabel("Word Builder");
    add(titleLabel, BorderLayout.PAGE_START);
    
    // main panel
    add(_____________________);
    
    _____________ letterPanel = ____________________;
    mainPanel.________________;
 
      ...

Get hands-on with 1200+ tech skills courses.