title: Java Swing: main class wait until JFrame is closed
body: <p>I need some help with a simple java application which makes use of two jframe to get some input parameters. Here's a sketch of my code: </p>
  
  <pre><code>//second jframe, called when the button OK of the first frame is clicked
  public class NewParamJFrame extends JFrame{
    ...
  }
  
  //first jframe
  public class StartingJFrame extends JFrame{
    private static  NewParamJFrame newPFrame = null;
    private JTextField gnFilePath;
    private JButton btnOK;
  
    public StartingJFrame(){
              //..
      initComponents();
    }
  
    private void initComponents(){
       btnOK.addActionListener(new ActionListener(){
        public void actionPerformed(ActionEvent e){
          try{
          EventQueue.invokeAndWait(new Runnable(){
             public void run() {
                 try {
                 newPFrame = new NewParamJFrame();
                 newPFrame.setVisible(true);
                 } catch (Exception e) {
                 e.printStackTrace();
                 }
             }
           });
          }
          catch(InvocationTargetException e2) {} 
          catch(InterruptedException e1){}
          dispose();
        }
    }
  
    public String getText(){
         return gnFilePath.getText();
    }
  }
  
  public class Main {
    private static StartingJFrame begin = null;
    public static void main(String[] args) {
       try{
          EventQueue.invokeAndWait(new Runnable(){
              public void run() {
                  try {
                      begin = new StartingJFrame();
                      begin.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
      catch(InvocationTargetException e) {} 
      catch(InterruptedException e1){}
  
      String s= begin.getText();
  
      //...use s ...
    }
  }
  </code></pre>
  
  <p>The call to getText() causes a NullPointerException. I want the main class to wait until the frames are closed but I don't know how to do. I'm using swing for the first time.</p>