title: Java - Waiting for some type of key press to continue
body: <p>What is the best way to implement a "press x to continue" type of thing in Java?</p>
  
  <p>Specifically, I have a custom class which extends JFrame and a custom class which extends JPanel. I have a Main.java (which has an instance of my JFrame class), and there is a point where I do not want to continue until the user has pressed the space bar:</p>
  
  <p>Main.java:</p>
  
  <pre><code>...code...
  frame.waitForSpace();
  ...more code which gets executed only after space is pressed...
  </code></pre>
  
  <p>So, in my frame class, how should I implement this:</p>
  
  <p>MyFrame.java:</p>
  
  <pre><code>/* This method only finishes when the space bar is pressed */
  public void waitForSpace() {
  
  }
  </code></pre>
  
  <p>By the way, I have the KeyListener on my JFrame which works when the space button is pressed. But I'm not quite sure how to incorporate that into what I'm trying to do.</p>
  
  <p>Example code would be awesome!</p>