Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: help building up GUI for poker game

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post help building up GUI for poker game

    hi, im new to the forums and to programing itself, and im trying to build up a simple swing/awt GUI for my bluej project wich simulates a 5 card poker game.
    thanks for the help

    basicaly i would like to import cards to make the gui more nice, and make sume buttons to the array that chooses the cards u want to change.

    thanks for the help
    here is my code
    import java.util.Random;
    import java.util.ArrayList;
    public class Poker
    {
        private Random rnd;
        private int cardA;
        private int card2;
        private int card3;
        private int card4;
        private int card5;
        private int card6;
        private int card7;
        private int card8;
        private int card9;
        private int card10;
        private int cardJ;
        private int cardQ;
        private int cardK;
        private int[] hand;
        private int isTwoOfAKind;
        private int isTreeOfAKind;
        private int isFull;
        private int isPoker;
        private int isStraight;
        public Poker()
        {
            rnd = new Random();
            hand = new int[5];
            shoufleCards();
            fillHand();
            printHand();
            isTwoOfAKind();
            isTreeOfAKind();
            isFull();
            isStraight();
            isPoker();
            System.out.println("choose the cards u want to change");
        }
        public void shoufleCards()
        {
            cardA = rnd.nextInt(13)+1;
            card2 = rnd.nextInt(13)+1;
            card3 = rnd.nextInt(13)+1;
            card4 = rnd.nextInt(13)+1;
            card5 = rnd.nextInt(13)+1;
        }
        public void fillHand()
        {
            hand[0] = cardA;
            hand[1] = card2;
            hand[2] = card3;
            hand[3] = card4;
            hand[4] = card5;
        }
        public int[] getHand()
        {
            return hand;
        }   
        public void printHand()
        {
            for(int index = 0; index < hand.length; index++)
            {
                if(hand[index]==1)
                {
                    System.out.println("A");
                }
                else if(hand[index]==11)
                {
                    System.out.println("j");
                }
     
                else if(hand[index]==12)
                {                
                    System.out.println("q");
                }
                else if(hand[index]==13)
                {                
                    System.out.println("k");
                }
                else
                {
                    System.out.println(hand[index]);
                }
            }
        }
        public void chooseCards(int[] chooseCards)//inside the parameter u need to place the position of the card u want to change
        {        
            for(int index = 0;index < chooseCards.length;index++)
            {
                int a = chooseCards[index];
                hand[a] = rnd.nextInt(13)+1;
            }
            printHand();
            isTwoOfAKind = 0;
            isTreeOfAKind = 0;
            isFull = 0;
            isStraight = 0;
            isPoker = 0;
            isTwoOfAKind();
            isTreeOfAKind();
            isFull();
            isStraight();
            isPoker();
        }
        public void isTwoOfAKind()
        {
            int A = 0;
            int two = 0;
            int tree = 0;
            int four = 0;
            int five = 0;
            int six = 0;
            int seven = 0;
            int eight = 0;
            int nine = 0;
            int ten = 0;
            int J = 0;
            int Q = 0;
            int K = 0;
     
            for(int index = 0; index < hand.length;index++)
            {
                if(hand[index]==1) A++;
                if(hand[index]==2) two++;
                if(hand[index]==3) tree++;
                if(hand[index]==4) four++;
                if(hand[index]==5) five++;
                if(hand[index]==6) six++;
                if(hand[index]==7) seven++;
                if(hand[index]==8) eight++;
                if(hand[index]==9) nine++;
                if(hand[index]==10) ten++;
                if(hand[index]==11) J++;
                if(hand[index]==12) Q++;
                if(hand[index]==13) K++;
            }
            if(A == 2)
            {
                    System.out.println("u got two of a kind with, aces");
                    isTwoOfAKind++;
            }
            if(two == 2)
            {
                    System.out.println("u got two of a kind with, twos");
                    isTwoOfAKind++;
            }
            if(tree == 2)
            {
                    System.out.println("u got two of a kind with, trees");
                    isTwoOfAKind++;
            }
            if(four == 2)
            {
                    System.out.println("u got two of a kind with, fours");
                    isTwoOfAKind++;
            }
            if(five == 2)
            {
                    System.out.println("u got two of a kind with, fives");
                    isTwoOfAKind++;
            }
            if(six == 2)
            {
                    System.out.println("u got two of a kind with,");
                    isTwoOfAKind++;
            }
            if(seven == 2)
            {
                System.out.println("u got two of a kind with, sevens");
                isTwoOfAKind++;
            }
            if(eight == 2)
            {
                System.out.println("u got two of a kind with, eights");
                isTwoOfAKind++;
            }
            if(nine == 2)
            {
                System.out.println("u got two of a kind with, nines");
                isTwoOfAKind++;
            }
            if(ten == 2)
            {
                System.out.println("u got two of a kind with, tens");
                isTwoOfAKind++;
            }
            if(J == 2)
            {
                System.out.println("u got two of a kind with, Js");
                isTwoOfAKind++;
            }
            if(Q == 2)
            {
                System.out.println("u got two of a kind with, Qs");
                isTwoOfAKind++;
            }
            if(K == 2)
            {
                System.out.println("u got two of a kind with, Ks");
                isTwoOfAKind++;
            }
     
        }
        public void isTreeOfAKind()
        {
            int A = 0;
            int two = 0;
            int tree = 0;
            int four = 0;
            int five = 0;
            int six = 0;
            int seven = 0;
            int eight = 0;
            int nine = 0;
            int ten = 0;
            int J = 0;
            int Q = 0;
            int K = 0;
                    for(int index = 0; index < hand.length;index++)
            {
                if(hand[index]==1) A++;
                if(hand[index]==2) two++;
                if(hand[index]==3) tree++;
                if(hand[index]==4) four++;
                if(hand[index]==5) five++;
                if(hand[index]==6) six++;
                if(hand[index]==7) seven++;
                if(hand[index]==8) eight++;
                if(hand[index]==9) nine++;
                if(hand[index]==10) ten++;
                if(hand[index]==11) J++;
                if(hand[index]==12) Q++;
                if(hand[index]==13) K++;
            }
            if(A == 3)
            {
                    System.out.println("u got tree of a kind with, Aces");
                    isTreeOfAKind++;
            }
            if(two == 3)
            {
                    System.out.println("u got tree of a kind with, twos");
                    isTreeOfAKind++;
            }
            if(tree == 3)
            {
                    System.out.println("u got tree of a kind with, trees");
                    isTreeOfAKind++;
            }
            if(four == 3)
            {
                    System.out.println("u got tree of a kind with, fours");
                    isTreeOfAKind++;
            }
            if(five == 3)
            {
                    System.out.println("u got tree of a kind with, fives");
                    isTreeOfAKind++;
            }
            if(six == 3)
            {
                    System.out.println("u got tree of a kind with, sixes");
                    isTreeOfAKind++;
            }
            if(seven == 3)
            {
                    System.out.println("u got tree of a kind with, sevens");
                    isTreeOfAKind++;
            }
            if(eight == 3)
            {
                 System.out.println("u got tree of a kind with, eights");
                 isTreeOfAKind++;
            }
            if(nine == 3)
            {
                 System.out.println("u got tree of a kind with, nines");
                 isTreeOfAKind++;
            }
            if(ten == 3)
            {
                 System.out.println("u got tree of a kind with,tens");
                 isTreeOfAKind++;
            }
            if(J == 3)
            {
                 System.out.println("u got tree of a kind with, Js");
                 isTreeOfAKind++;
            }
            if(Q == 3)
            {
                 System.out.println("u got tree of a kind with, Qs");
                 isTreeOfAKind++;
            }
            if(K == 3)
            {
                 System.out.println("u got tree of a kind with, Ks");
                 isTreeOfAKind++;
            }
        }
        public void isPoker()
        {
            int A = 0;
            int two = 0;
            int tree = 0;
            int four = 0;
            int five = 0;
            int six = 0;
            int seven = 0;
            int eight = 0;
            int nine = 0;
            int ten = 0;
            int J = 0;
            int Q = 0;
            int K = 0;
            for(int index = 0; index < hand.length;index++)
            {
                if(hand[index]==1) A++;
                if(hand[index]==2) two++;
                if(hand[index]==3) tree++;
                if(hand[index]==4) four++;
                if(hand[index]==5) five++;
                if(hand[index]==6) six++;
                if(hand[index]==7) seven++;
                if(hand[index]==8) eight++;
                if(hand[index]==9) nine++;
                if(hand[index]==10) ten++;
                if(hand[index]==11) J++;
                if(hand[index]==12) Q++;
                if(hand[index]==13) K++;
            }
            if(A == 4)
            {
                    System.out.println("u got poker with, Aces");
                    isPoker++;
            }
            if(two == 4)
            {
                    System.out.println("u got poker with, twos");
                    isPoker++;
            }
            if(tree == 4)
            {
                    System.out.println("u got poker with, trees");
                    isPoker++;
            }
            if(four == 4)
            {
                    System.out.println("u got poker with, fours");
                    isPoker++;
            }
            if(five == 4)
            {
                    System.out.println("u got poker with, fives");
                    isPoker++;
            }
            if(six == 4)
            {
                    System.out.println("u got poker with, sixes");
                    isPoker++;
            }
            if(seven == 4)
            {
                    System.out.println("u got poker with, sevens");
                    isPoker++;
            }
            if(eight == 4)
            {
                 System.out.println("u got poker with, eights");
                 isPoker++;
            }
            if(nine == 4)
            {
                 System.out.println("u got poker with, nines");
                 isPoker++;
            }
            if(ten == 4)
            {
                 System.out.println("u got poker with, tens");
                 isPoker++;
            }
            if(J == 4)
            {
                 System.out.println("u got poker with, Js");
                 isPoker++;
            }
            if(Q == 4)
            {
                 System.out.println("u got poker with, Qs");
                 isPoker++;
            }
            if(K == 4)
            {
                 System.out.println("u got poker with, Ks");
                 isPoker++;
            }
        }   
        public void isFull()
        {
            if((isTwoOfAKind == 1) && (isTreeOfAKind == 1))
            {
                System.out.println("u got full");
                isFull++;
            }
        }
        public void isStraight()
        {
            int A = 0;
            int two = 0;
            int tree = 0;
            int four = 0;
            int five = 0;
            int six = 0;
            int seven = 0;
            int eight = 0;
            int nine = 0;
            int ten = 0;
            int J = 0;
            int Q = 0;
            int K = 0;        
            for(int index = 0; index < hand.length;index++)
            {            
                if(hand[index]==1) A++;
                if(hand[index]==2) two++;
                if(hand[index]==3) tree++;
                if(hand[index]==4) four++;
                if(hand[index]==5) five++;
                if(hand[index]==6) six++;
                if(hand[index]==7) seven++;
                if(hand[index]==8) eight++;
                if(hand[index]==9) nine++;
                if(hand[index]==10) ten++;
                if(hand[index]==11) J++;
                if(hand[index]==12) Q++;
                if(hand[index]==13) K++;
            }
            if((A == 1)&&(two == 1)&&(tree == 1)&&(four == 1)&&(five == 1)&&(six == 1))
            {
                    System.out.println("u got Straight!");
                    isStraight++;
            }
            if((two == 1)&&(tree == 1)&&(four == 1)&&(five == 1)&&(six == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((tree == 1)&&(four == 1)&&(five == 1)&&(six == 1)&&(seven == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((four == 1)&&(five == 1)&&(six == 1)&&(seven == 1)&&(eight == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((five == 1)&&(six == 1)&&(seven == 1)&&(eight == 1)&&(nine == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((six == 1)&&(seven == 1)&&(eight == 1)&&(nine == 1)&&(ten == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((seven == 1)&&(eight == 1)&&(nine == 1)&&(ten == 1)&&(J == 1))
            {
                System.out.println("tenes escalera");
                isStraight++;
            }
            if((eight == 1)&&(nine == 1)&&(ten == 1)&&(J == 1)&&(Q == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((nine == 1)&&(ten == 1)&&(J == 1)&&(Q == 1)&&(K == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
            if((ten == 1)&&(J == 1)&&(K == 1)&&(Q == 1)&&(A == 1))
            {
                System.out.println("u got Straight!");
                isStraight++;
            }
        }
    }
    Last edited by Pencil; October 26th, 2010 at 01:13 PM.


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: help building up GUI for poker game

    ...did you have a question?

  3. #3
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help building up GUI for poker game

    shure i do i need, as the thread sais i want to create a GUI for this program, my idea is to be able to see the cards instead of numbers in the console. and have buttons that call for the methods. but i have no clue where to start.
    thanks

  4. #4
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: help building up GUI for poker game

    i have no clue where to start.
    Fair enough.
    Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    db

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: help building up GUI for poker game

    Hello Pencil,

    Welcome to the forums.

    Have you ever created a basic GUI before?

    You can get started here - Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

    Don't forget to look here for code examples - Java Code Snippets and Tutorials - Java Programming Forums
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Junior Member
    Join Date
    Oct 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help building up GUI for poker game

    thanks a lot Darryl.Burke and JavaPF these tutorial might just be the thing im looking for

Similar Threads

  1. Issue Building Graph in Adjacency Matrix
    By mike.s in forum What's Wrong With My Code?
    Replies: 7
    Last Post: October 22nd, 2010, 02:44 PM
  2. Building Table of Specified Rows and Columns
    By wale89 in forum Java Servlet
    Replies: 1
    Last Post: August 3rd, 2010, 08:57 AM
  3. Replies: 5
    Last Post: June 10th, 2010, 10:19 AM
  4. Please help Me out with this poker Problem
    By ckrisasa in forum Java Networking
    Replies: 1
    Last Post: November 29th, 2009, 02:31 AM
  5. Building a Menu List
    By websey in forum AWT / Java Swing
    Replies: 1
    Last Post: November 15th, 2009, 10:34 AM