This is a continuation of previous works.
You would need to read "Console Poker" first.
Quick Start
If you just want to play the game, go to the Source Code section below.
Game Flow
There would be a deal button in the screen. Once it is pressed, five cards would be dealt to you.
If the initial deal forms a winning pattern, you would hold all the cards and press the deal button again.
Otherwise, you may hold any number of cards, hoping that the second deal would improve the chance of winning.
The cards are actually buttons and therefore are clickable objects. Clicking on them would change the hold status.
Image Buttons
We can apply a image to the JButton component. But first of all, we must have the card image on hand.
Drawing a playing card is not difficult, and this is already demonstrated in a previous article. For details, read :
Note that VideoPoker.java will be the only source file created in this article, all other source files come from previous works. This is one of the important software design principle :
Don't reinvent the wheel
Poker Patterns
The table of winning patterns and payouts are shown in the previous article "Console Poker"
The game flow logic are inside the source file ConsolePoker.java in the above article. This file will be reused here.
Design
Ideally, the GUI should be separated from the game logic, this is not 100% true in this sample, but it is getting close.
- ConsolePoker.java - game flow logic
- VideoPoker.java - GUI components
- Poker.java - the pattern matcher
- Pattern.java - define pattern constants
- CardPanel.java - create card images
Source Code
You will need all the five java files in the same folder.
- VideoPoker.java - GUI components
- ConsolePoker.java - game flow logic
- Poker.java - the pattern matcher
- Pattern.java - define pattern constants
- CardPanel.java - create card images
To compile :
javac *.javaTo run :
javac VideoPokerOnly VideoPoker.java is new in this article, all other source files are from previous works. Anyway, all of them will be listed here for your convenience.
ConsolePoker.java
Originally defined in : Console Poker
Poker.java
Originally defined in : Console Poker
Pattern.java
Originally defined in : Console Poker
CardPanel.java
Originally defined in : How to display a deck of playing card in a panel ?