title: Stop code until a condition is met
body: <p>How can you create a function or component etc that will stop all running code until a condition is met? </p>
  
  <p>For example the same way as a JOptionPane will do, if I have this for example:</p>
  
  <pre><code>JOptionPane.showInputDialog(null, "Hello", "Title", 1);
  </code></pre>
  
  <p>Within a function etc and then print to the console afterwards it it will not print until I close the JOptionPane. </p>
  
  <p>I am guessing this component has some sort of thread setup built in to do this but how could I duplicate that with my own functions?</p>
  
  <p>So say for example I wanted to make JFrames delay everything until it was closed so it acts like a JOptionPane.</p>
  
  <p>Or for example have a function that had multiple inputs which got updated and inside it did some maths with those and if it was a certain value returned a boolean, but then everything else but those was paused until the true boolean was returned.</p>
  
  <p>I am guessing the solution is some sort of thread setup but I am quite new to Java and when I have coded in the past I have not really used threads so I cannot create a good stop-start/pause-run style function system yet. </p>
  
  <p>Does anyone have any suggestions how to achieve this or better yet code examples showing this type of thing working?</p>