10 Replies - 625 Views - Last Post: 12 April 2010 - 03:38 PM Rate Topic: -----

#1 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Poker Bidding problem

Posted 10 April 2010 - 03:44 PM

I'm willing to admit that I didn't search this, but only because I didn't know what to search for. so here it is. my main function makes a new peopleFrame for each person playing. peopleFrame is just an extended JFrame which also is an actual player (well not yet, but that's my plan). after i have all the people (up to 8) I want the main function to cycle through each peopleFrame and tell it that they need to bet. so far i can only get it to tell my first peopleFrame it's their turn to bet. (peopleFrame.yourTurn();) on peopleFrame i have on the 2 buttons on my southPanel bet and fold. when i press either one of those i want my main function record what happened and go to next player...

and i have NO CLUE how to get my for loop to wait for my button commands. can i get some help please?

Is This A Good Question/Topic? 0
  • +

Replies To: Poker Bidding problem

#2 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Poker Bidding problem

Posted 10 April 2010 - 04:49 PM

set up an action listener so that once either one of those buttons are pressed, it changes a boolean variable (e.g turnIsOver) to true, which in turn triggers the next player on the list's turn to be called
Was This Post Helpful? 1
  • +
  • -

#3 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Poker Bidding problem

Posted 10 April 2010 - 06:45 PM

i know how to set up actionlisteners for the same program, but in this case i'm using 2 programs.
junkpoker.java is my main program that sets up all of my peopleFrames (my players) it does that by using a JOptionPane to get how many players than sets up a for loop and create that many peopleFrames. Now I don't have a problem making a actionlistener for peopleFrames, but how will junkpoker.java know that i pressed anything so that it can go to the next peopleFrames... like something like

gamers = new PlayerFrame[peoplePlaying]; //extends JFrame, but is also the players
//instantiate all the player frames, and give everyone their cards
//...
//...
int pot = 0;
for (int a=0;a<peoplePlaying;a++)
{
  pot += gamers[a].getBetorFold(); //get what they bet from that PlayerFrame
}


Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10778
  • View blog
  • Posts: 40,135
  • Joined: 27-December 08

Re: Poker Bidding problem

Posted 10 April 2010 - 08:26 PM

You could use an inner class for the player frame, encapsulated in the class for the main frame. So something like:
class Main extends JFrame{
  
   Player[] players;

   class Player extends JInternalFrame implements ActionListener{}
}



If you use CardLayout for your Main JFrame, you can have the actionPerformed() method in the Player class flip cards. So basically, when the JButton is clicked in your Player object, have it flip to the next() Player with Main() as the Container.

For more information on CardLayout, check out the API:
http://java.sun.com/...CardLayout.html
Was This Post Helpful? 1
  • +
  • -

#5 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Poker Bidding problem

Posted 10 April 2010 - 09:45 PM

What I was saying about the boolean though is that you can make it a public variable so that other programs have access to it as long as they are in the same package. Once the Action listener is tripped and sets the boolean to true, have something set up in junkpoker.java (an if statement in your game loop that only trips when the boolean in the PlayerFrame program is true) that increments a variable to move to the next player and then reset the boolean to false again.
Was This Post Helpful? 1
  • +
  • -

#6 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10778
  • View blog
  • Posts: 40,135
  • Joined: 27-December 08

Re: Poker Bidding problem

Posted 10 April 2010 - 09:48 PM

With an inner class, the Player ActionListener will have direct access to the CardLayout object, allowing one Player's button click to move to the next Player frame.
Was This Post Helpful? 1
  • +
  • -

#7 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Poker Bidding problem

Posted 11 April 2010 - 05:15 AM

ok, i see what your saying now. Thank you guys very much, I'll try that out and see what i can come up with.
Was This Post Helpful? 0
  • +
  • -

#8 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Poker Bidding problem

Posted 11 April 2010 - 06:40 AM

awesome, ok so I made my buttons in playerFrame public, added a function called setButtonState(boolean) which disables, or enables, both buttons and sets a label to either null or "Your turn". In junkpoker.java I added a actionListener(this) to each of those buttons, than did a check for bet or fold and updated the gamers[yourTurn].setButtonState(false) than gamers[yourTurn++].setButonState(true) to reflect whose turn it was (and yes i do check to make sure that i don't go out of bounds)

oh and i don't want to use cardlayout because I plan on adding a server client function so i can play accross home network. during poker round you'll only see your cards and a blank blue card (back of card) for everyone else who is playing. than when betting is done everyone's cards are shown and a bingo round begins (dealers hand is thrown away) ..and a few more steps.. don't want to have a huge long post.

now i have a similar question. I have 5 canvas's (overridden to paint a picture of a card) on a JPanel in each playerFrame. they all display exactly like i want them too, but for the bingo round the dealer flips up a card and if you have that rank of card (suit doesn't matter) you put a coin on that card until you fill up all 5 cards.. I'm not sure at how about to get this done. I know i can add a mouse listener to my canvaseee (that's plural now :) and now i know i can pass information. Would i just have a boolean bingo that goes true when i fill up all 5 cards and in than make a code similiar to this?

boolean bingo = false;
while (!bingo)
{
  dealer.getNewCard();
  for(int a=0;a<peoplePlaying;a++
    if (gamer[a].hasBingo)
      bingo=true
}



or is their a better way?

EDIT:

oh and maybe i should override the ActionEvent??? but how do i do that? all i know how to override is the toString() function.

This post has been edited by immeraufdemhund: 11 April 2010 - 07:36 AM

Was This Post Helpful? 0
  • +
  • -

#9 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Poker Bidding problem

Posted 11 April 2010 - 06:50 AM

I'm sure there is a much cleaner way, but booleans are my best friend. I would go with this approach, but that's just my preference because I know I can make things work with boolean states to them
Was This Post Helpful? 0
  • +
  • -

#10 immeraufdemhund  Icon User is offline

  • D.I.C Regular

Reputation: 79
  • View blog
  • Posts: 495
  • Joined: 29-March 10

Re: Poker Bidding problem

Posted 12 April 2010 - 03:04 PM

thank you so much for all the help you guys have been doing. So I decided that i was going about my program for the wrong approach. I'm now deciding that i'm going to have 2 frames. first frame will have my cards, my money. and the second frame will have all the other people's cards and money left, jackpot, and a chat room.

Like i said before i want this to be a local network program. I read up on the tutorial on server/client bit. and this is were my question is too. I did a lot of copying of his code into mine and I am able to ONLY get one other client computer to connect to mine.(either my own by running two instances, or one on another laptop of mine) My problem is is that one I have to always have the same server "Ert-PC". I read up on another thread about UDP, and TCP, and RMI stuff...and I "think" it's what i need only because when i play starcraft multi-player i have to select the udp option to play over my local network. So how do i get my "server" to broadcast my signal?

I never realized how deep and complex a "simple" program is, but i've been finding out right quick. Thank you again for all the help and suggestions given so far. I've been trying to add rep points when i can for you guys.
Was This Post Helpful? 0
  • +
  • -

#11 Luckless  Icon User is offline

  • </luck>
  • member icon

Reputation: 293
  • View blog
  • Posts: 1,146
  • Joined: 31-August 09

Re: Poker Bidding problem

Posted 12 April 2010 - 03:38 PM

Haha, rep points don't mean much, but we appreciate it.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1