title: Calling a method everytime the text in JPasswordField is altered
body: <p><strong>--EDIT--</strong><br>
  I've got a JTextField and I want a method (let it be just print statement for now) to be called everytime someone changes (types or deletes) a character in the JTextField. The purpose behind it is for the method to instantly check whether whatever is typed satisfies certain conditions. Thanks to your help I managed to write: </p>
  
  <pre><code>public class MyDocumentListener implements DocumentListener {
  
      public void insertUpdate(DocumentEvent e) {
          updateLog(e, "inserted into");
      }
      public void removeUpdate(DocumentEvent e) {
          updateLog(e, "removed from");
      }
      public void changedUpdate(DocumentEvent e) {
          //Plain text components do not fire these events
      }
  
      public void updateLog(DocumentEvent e, String action) {
          System.out.println("should call the method here");
      }
  }
  </code></pre>
  
  <p>The JTextField code:</p>
  
  <pre><code>    JTextField passwordField = new JTextField();
      passwordField.getDocument().addDocumentListener(new MyDocumentListener());
      passwordField.getDocument().putProperty("name", "Text Field");
  </code></pre>
  
  <p>The problem I'm getting now is that I need to use</p>
  
  <pre><code>String textFieldPassword = passwordField.getText();
  </code></pre>
  
  <p>but it returns <code>NullPointerException</code>. I am assuming that this is because I added the <code>DocumentListener</code> and should be operating on <code>DocumentEvent</code> now. But I don't really know how to do it.</p>