Make Java method wait for user to click button

Joined
Dec 7, 2009
Messages
1
Reaction score
0
Hello VR,

I am working on a program, a basic poker game. I've run into a problem I can't seem to solve for the life of me, after hours of googling I thought I'd ask here.

I have a Dealer class that basically controls the back end of the came, and it calls various methods in pokerGUI to update the display when it computes the flop and computer player actions. However, when it is the human player's turn, It calls a method in the pokerGUI to display certain buttons depending on the available options (ie, if no one has bet it displays a check button and bet button or if someone has bet, call button/fold button/raise button). Then the player ideally would click a button, and the GUI would pass back the info (including a double if the player placed a bet). My problem is that when the Dealer calls the GUI via getHumanAction(), it expects a double in return. But GUI does not immediately have a double to return, since it must wait for the player to decide and click the appropriate action. Below is the code in Dealer.java

Code:
  public double getPlayerBet(double currentBet) 
    {
    	
    	return board.getHumanAction(currentBet);

    }

and the code in the GUI just initializes some buttons and graphics and adds appropriate action listeners, then finally returns the value of the players choice. The problem is again that getHumanAction doesn't immediately return a double. What I want to do is somehow put a pause in getHumanAction just before it returns the double, and then have it continue when a button is clicked (and the double has the users input). So basically getHumanAction would stop....then when the player clicks a button (for example, check), the ActionEvent would cause getHumanAction would continue, returning the info the player provided when it clicked the button. How do I pause the method without freezing my entire program?
I've tried:
-Wait/notify: Regardless of where I put these, as soon as it hits wait() the entire GUI blanks out because it freezes the EVT (I think?)
-sleep() also freezes the entire GUI
all the thread manipulating methods don't work, they freeze the GUI. I tried
putting the wait functions in their own separate threads, but I just can't seem to not freeze the GUI.


Thanks in advance for any help, I'm dying here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top