title: How to Pause Swing in Java?
body: <ul>
  <li>I have a main java program named MainProgram.java</li>
  <li>MainProgram.java has its member as a JFrame MyFrame</li>
  <li>The frame MyFrame has a JPanel in it called MyPanel</li>
  <li>I have overriden the PaintComponent of MyPanel to draw an image.</li>
  </ul>
  
  <p>MainProgram.java constantly gets a feed from a video file and calls the paintComponent of MyPanel.</p>
  
  <p>What I want to do is for the program to wait until I press Enter key. Only when I press the Enter key, should the next frame be taken from the video and displayed.</p>
  
  <ol>
  <li><p>Thread.sleep I saw in so many places cannot be used since, then it cannot listen for key
  press.</p></li>
  <li><p>A Timer cannot be used since I am not timing anything.</p></li>
  </ol>
  
  <p>The dirty workaround I used was</p>
  
  <pre><code>boolean x = false;
  .
  .
  .
  while(x==false);
  .
  .
  .
  onKeyPressed()
  {
      x=true;
      //get frame from video
      //call paintComponent
      x=false;
  }
  </code></pre>
  
  <p>Anyone can give a good solution please?</p>