Define Required Classes
Learn to read an image for setting up a tile in a window and create a main window.
We'll cover the following
In this lesson, we will create two classes required for the game.
Initial setup for LetterPanel
Next we will need some letter panels.
- Create a new class called
LetterPanel
in theletterPanel.java
ofwordbuilder
package, with superclassJPanel
and with no stub code. - Add a private static final long instance variable called
serialVersionUID
, set to1L
. - Add a private static final
Color
calledBROWN
, set to a new color withred
,green
, andblue
values of49
,22
, and3
. Use Color’s constructor that allows you to enter integers for red, green, and blue. - Add a private static final string called
IMAGENAME
, set to “WoodTile.jpg”. - Add a private string instance variable called
letter
, initialized to an empty string. - Add a private integer instance variable called
points
, initialized to-1
. - Add a private
BufferedImage
instance variable calledimage
, initialized tonull
. - Add a private integer instance variable called
size
, initialized to40
. - Add two private
Font
instance variables calledbigFont
andsmallFont
. Both should be in the Dialog family and bold.bigFont
should be size30
andsmallFont
should be size12
. (Hint: use Font’sDIALOG
andBOLD
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.