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.
- Add a private
JPanel
instance variable calledmainPanel
, initialized by calling JPanel’s constructor. - In the main panel section of
initGUI()
, addmainPanel
to the center of the window. Use JFrame’sadd()
method and BorderLayout’sCENTER
variable. - Create a new
LetterPanel
object calledletterPanel
, with the letter “A” and 1 point, and addletterPanel
tomainPanel
using JPanel’sadd()
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.