title: How do you temporarily pause a loop until a button is pressed in java
body: <p>How can I make a loop temporarily pause while i wait for a button to be pressed? Iv been looking around for a while, and I cant seem to find it, thought I would try here.</p>
  
  <p>EDIT-</p>
  
  <p>I am creating a blackjack game, I added a gui to it with buttons, HITME and STAND once the game gets to the point in the loop where i need to get player input to either, HITME or STAND I added buttons to execute that, but I cant figure out how to pause the loop to check and see if the button was pressed, and which one to continue.</p>
  
  <p>what i have tried is this:</p>
  
  <pre><code> (othercode)  
  g.printPlayerCards(p1);
              g.totalworth(p1);
              thing.messagetop("Your total card amount is: " + p1.getTotalWorth());
              thing.messagetop("Hit me? or stay?");
              thing.waitonbutton();
  
  
  public void waitonbutton(){
          wantingtobeclick = 1;
          do{
              while(!(hitme == 0)){
                  hitme = 0;
                  wantingtobeclick =0;
              }
          }while(wantingtobeclick == 1);
      }
  
  public void actionPerformed(ActionEvent e) {
          if(wantingtobeclick == 1){
              if (e.getSource() == HitMe){
                  hitme = 1;
                  System.out.println("ICLICKEDHITME");
                  g.hitMe(player1);
                  waitonbutton();
              }
              if(e.getSource() == Stand){
                  hitme = 1;
                  g.changestandhit();
              }
          }
      }
  </code></pre>
  
  <p>It just stays in a infinite loop and doesn't continue on with the loop in main.</p>