title: Get the value of variable when it's not null
body: <p>I need to get value of password variable from PasswordFrame in my Main class when it is not <code>null</code>. Here is code of PasswordFrame:</p>
  
  <pre><code>public class PasswordFrame extends JFrame {
      static JTextField tf;
      static JButton button; 
      public String password;
      boolean isPassword = false;
      public PasswordFrame(){
          tf = new JTextField();
          button = new JButton("Enter");
          button.addActionListener(new ActionListener(){
              public void actionPerformed(ActionEvent e){
                  password =  tf.getText();
                  isPassword = true;
              }
  
          });
      }
  </code></pre>
  
  <p>I already have tried do it using this code:</p>
  
  <pre><code>public String getPassword(){
          while(!(isPassword)){
          }
          System.out.println("out");
          return password;
      }
  </code></pre>
  
  <p>But when I tried </p>
  
  <pre><code>PasswordFrame  passwordfield = new PasswordFrame();
  if (password.equals(passwordfield.getPassword())){
  //code
  }
  </code></pre>
  
  <p>"out" isn't printed and it can't exit <code>while</code> loop. Why? And how can I make PasswordFrame work correctly and return password.</p>
  
  <p>P.S. If you're going to downvote , tell me what can I improve to make my question more clear.</p>