title: Swing , Multiple Screens , Transfer of control
body: <p>I am developing a swing application. I am using two screens</p>
  
  <p>1.A button from screen1 will launch screen 2.</p>
  
  <p>PseudoCode :</p>
  
  <pre><code>ScreenA extends JFrame{
  
      onButtonClick(){
          Screen2.setVisible(true);
      }
      System.out.println("Hai");
  }
  
  Screen2 extends JFrame{
      onButtonClick{
           Hide this screen;
      }
  }
  </code></pre>
  
  <p>Now the output is :</p>
  
  <ol>
  <li>The screen 2 will be displayed 
  2.Hai will be printed.</li>
  </ol>
  
  <p>My Objective : I want to display hai only when a button from screen 2 is clicked and screen 2 dissppears.</p>
  
  <p>How do i achieve it ?</p>
  
  <p>I tried setting a flag for buttonclicked in screen two.
  But the program just passes through the condition and goes on to the next line . 
  How do i keep the control ?</p>