Results 1 to 1 of 1
  1. #1
    santeron is offline Member
    Join Date
    Apr 2011
    Athens, Greece
    Rep Power

    Question Design logic problem - Poker App

    Hello there,
    I've been coding a Texas Hold'em Odds Calculator for 2-3 weeks now. I've completed the functionality classes which run ok in cmd (tested most of the code maybe needs some more work but you get the idea).

    I've made a class named Table which is basically an API for controlling the other classes. Direct access is not needed to other classes (except some enums and the Card class).

    Now I'm trying to build a GUI that handles this table class graphically. There is the JFrame which just has a reference to the table object.
    I've also made a class named CardPanel which is basically a placeholder for painting cards on the table. It extends JPanel, has a custom paint method and some other methods and has a mouseClickListener that opens a dialog so you can change/clear the card represented from that CardPanel.
    The dialog that appears is a custom JDialog extension. It has a static method getCardDialog(Point) which is called when you want the dialog to be created (did that because I need the return value). Here is the code (removed unnecessary creating components code).

    Java Code:
    package TexasHoldemOddsInterface;
    import TexasHolemOdds.Card;
    import TexasHolemOdds.CardValue;
    import TexasHolemOdds.Suite;
    import java.awt.Dimension;
    import java.awt.Point;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.util.Arrays;
    import javax.swing.*;
     * @author Dimitris Klimis <dnklimis at>
    public class TempCardChooser extends JDialog implements ActionListener {
        int x, y;
        Point point;
        Suite suite;
        CardValue cardValue;
        CardAction cardAction = CardAction.CARD_CANCELED;
        JComboBox cbxSuites;
        JComboBox cbxValues;
        public enum CardAction {
        public TempCardChooser(Point point) {
            x = point.x;
            y = point.y;
            this.point = point;
            this.setLocation((int) (x - (this.getWidth() / 2.0)), (int) (y - (this.getHeight() / 2.0)));
        private void initComponents() {
            //creating the components
            btnCancel.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    cardAction = CardAction.CARD_CANCELED;
            JButton btnSave = new JButton("Save");
            btnSave.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    cardAction = CardAction.CARD_SAVED;
            JButton btnClear = new JButton("Clear");
            btnClear.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    cardAction = CardAction.CARD_CLEARED;
            //creating and placing components
        private CardAction getCardAction() {
            return cardAction;
        private Card getCard() {
            return new Card(suite, cardValue);
        public static Card getCardDialog(Point point) {
            TempCardChooser chooser = new TempCardChooser(point);
            if (chooser.getCardAction() == CardAction.CARD_SAVED) {
                return chooser.getCard();
            } else if (chooser.getCardAction() == CardAction.CARD_CLEARED) {
                return new Card(null, null);
            } else {
                return null;
        public void actionPerformed(ActionEvent e) {
            suite = Suite.values()[cbxSuites.getSelectedIndex()];
            cardValue = CardValue.values()[cbxValues.getSelectedIndex()];
    So this dialog returns a Card object to the CardPanel so it updates it's value and repaint itself.

    Now my problem. The way I do it, each CardPanel holds it's own card information and has no knowledge of other CardPanels' info. So it's possible to select the same card two times in two different CardPanels. Where should I put a list to know which cards are already played? Should I put a static ArrayList in CardPanel? I want to make something that makes sense and I'm not sure if that's the way to go. The JFrame surely shouldn't have a list like that. The Table object has a list like that but I don't want a CardPanel in GUI have a reference to the Table object.

    I don't know if I made my program's structure or logic clear. Please ask any clarification that you may need. Thx in advance... :)


    PS. Posted this question to OTN forums because I didn't get any answers here.
    Last edited by santeron; 05-25-2011 at 01:13 AM.

Similar Threads

  1. Texas Hold'em Poker
    By JohnPringle83 in forum Java Gaming
    Replies: 0
    Last Post: 05-05-2011, 06:40 AM
  2. Help with logic problem
    By jch02140 in forum New To Java
    Replies: 5
    Last Post: 01-01-2011, 12:39 PM
  3. Inheritance logic problem
    By Gloomy in forum New To Java
    Replies: 3
    Last Post: 08-28-2010, 09:23 AM
  4. Please help Me out with this poker Problem
    By ckrisasa in forum Networking
    Replies: 8
    Last Post: 12-03-2009, 02:59 PM
  5. problem with <logic:iterate> tag looping
    By tsaswathy in forum Web Frameworks
    Replies: 0
    Last Post: 09-27-2008, 01:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts