Fill Board with Tiles and Use Font Metrics
Learn to fill the board with tiles and align the letters and points on the tiles.
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.
- In
WordBuilder
class, add private static final integer instance variables calledROWS
,COLS
, andMAX
, set to8
,12
, and15
, respectively. - Add a private
LetterPanel
two-dimensional array instance variable calledboard
, withROWS
rows andCOLS
columns. - Add a private
JPanel
instance variable calledboardPanel
, 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.