MS-4811
Java Program #5
JFC/Swing
Components
Date Assigned: Monday, February 6, 2006
Now that we’ve covered the Java Delegation Event Model in detail and have also covered many JFC/Swing components, the objective is to make use of the component library to put a graphical user interface onto the Blackjack program from the previous lab assignment. To make the job easier, I’ve placed a blackjackcardimages.zip file on the course web page that contains 53 .gif files, one for each card face and one card back image. Add the card image to the Card class and write separate JFrame and JPanel subclasses to play the game. Use other JFC components in your user interface to make the game more enjoyable to the player. For instance, a ‘hit’ and ‘stand’ button would make it easy for the player to make their moves. As an enhancement (after all the basic functions are working), add a wager feature that manages how much a player is betting on the hand. This can be done with labels or textboxes. Be creative and see what other GUI widgets you can use to make the game enjoyable to play.
As a suggestion, I found it easy to ‘draw’ cards by using the ImageIcon class. An ImageIcon can be loaded from an image.gif file and can also be used to label a JButton instance. Using a button to hold the image means that I can use a layout manager to organize the display of the cards on the table (both the dealer’s cards and the player’s cards). Layout managers are a very useful feature to know about whenever a UI display is being constructed. Operations, such as resizing the window, are easily handled by the Layout Manager (who reorganizes the display and repaints the components automatically).
As always, once you have a working program, submit all the Java source files needed to run your game to blessing@msoe.edu.