If a top row tile is clicked, play it

Only the top row of tiles will need to be clickable. Because a played tile might have to be put back on the board, each tile must have a record of which column it was originally in.

  1. In initGUI(), set the column of the letterPanel after each letterPanel is created using LetterPanel’s setColumn() method.
  2. After the double for loop that created all the letter panels for the board, create a loop to repeat COLS times with an integer called col as the iteration variable.
  3. Add a mouse listener to each letter panel in the top row of the board. Use 0 and col as the indexes for each letter panel. Also, use JPanel’s addMouseListener() method, with a new MouseAdapter object as the parameter value. In the MouseAdapter, add a public method called mouseReleased(). The mouseReleased() method should take MouseEvent parameter called e, and return nothing.
  4. In mouseReleased():
    • Create a LetterPanel object called letterPanel, initialized by getting the source of e using MouseEvent’s getSource() method.
    • Call a new method called click(), passing letterPanel as the parameter value.

Note: The code will have a syntax error because click() does not exist yet.

    ...
    
  private void initGUI() {
 
      ...
 
    for(int row=0; row<ROWS; row++) {
      for(int col=0; col<COLS; col++) {
        LetterPanel letterPanel = letters.pickATile();
        letterPanel.________________;
        board[row][col] = letterPanel;
        boardPanel.add(letterPanel);
      }
    }
    
    for(_________________) {
      board[___][___].addMouseListener(________________ {
        _____________ mouseReleased(__________) {
          ______________ letterPanel = _______________;
          _________(letterPanel);
        }
      });
    }
      ...

Get hands-on with 1200+ tech skills courses.