Create a Window and a Card Panel
Learn to create a Baker's Dozen game window to display the cards and create a class for cards.
Objects on a panel
If you want multiple objects painted on a panel, the panel could keep track of where and how to draw each object. However, with class definitions for each of the objects, writing the program is easier if each object keeps track of where and how to draw itself.
Doing initial setup for BakersDozen
class
The cards.png image is now complete and we can start writing the game.
We have provided a class called
BakersDozen
in theBakersDozen.java
ofbakersdozen
package, with superclassJFrame
containing stub formain()
.
- Add a private static final long instance variable called
serialVersionUID
, set to1L
. - Add a
BakersDozen
constructor with no parameters. In the constructor:- Call
initGUI()
. - Set the window’s title to “Baker’s Dozen”, disable resizing, pack the window, center the window, make the window visible, and set the window to exit when closed.
- Call
- Create a new private method called
initGUI()
. It should take no parameters and return nothing. IninitGUI()
, add aTitleLabel
with text “Baker’s Dozen” to the top of the window.
public class BakersDozen extends JFrame {
private static final long serialVersionUID = 1L;
___________ BakersDozen(______) {
__________();
______________;
______________;
______________;
______________;
______________;
______________;
}
_______________ initGUI() {
____________ titleLabel = _________________;
add(_______________);
}
}
Get hands-on with 1200+ tech skills courses.