Define Required Classes

Learn to read an image for setting up a tile in a window and create a main window.

In this lesson, we will create two classes required for the game.

Initial setup for LetterPanel

Next we will need some letter panels.

  1. Create a new class called LetterPanel in the letterPanel.java of wordbuilder package, with superclass JPanel and with no stub code.
  2. Add a private static final long instance variable called serialVersionUID, set to 1L.
  3. Add a private static final Color called BROWN, set to a new color with red, green, and blue values of 49, 22, and 3. Use Color’s constructor that allows you to enter integers for red, green, and blue.
  4. Add a private static final string called IMAGENAME, set to “WoodTile.jpg”.
  5. Add a private string instance variable called letter, initialized to an empty string.
  6. Add a private integer instance variable called points, initialized to -1.
  7. Add a private BufferedImage instance variable called image, initialized to null.
  8. Add a private integer instance variable called size, initialized to 40.
  9. Add two private Font instance variables called bigFont and smallFont. Both should be in the Dialog family and bold. bigFont should be size 30 and smallFont should be size 12. (Hint: use Font’s DIALOG and BOLD variables.)
package wordbuilder;
 
import java.awt.Color;
import java.awt.Font;
import java.awt.image.BufferedImage;
 
import javax.swing.JPanel;
 
public class LetterPanel extends JPanel {
  private static final long serialVersionUID = 1L;
  ____________ BROWN = ____;
  ____________ IMAGENAME = ____________;
  
  ____________ letter = ____;
  ____________ points = ____;
  ____________ image = ____;
  ____________ size = ____;
  ____________ bigFont = ____________;
  ____________ smallFont = ____________;
}

Get hands-on with 1200+ tech skills courses.