title: How to remove the last character in a JTextField when delete key is pressed
body: <p>I want to use a key listener to detected each time the user enters text into a field. Each time the key event is triggered I want to get the <code>length()</code> of the text in the <code>JTextField</code>. If the <code>length &gt;= limit</code> then I want to disable editing. However, if the <strong>delete key</strong> is pressed I want to remove the <strong>last character</strong> in the <code>JTextField</code> and <code>setEditable(true)</code>.</p>
  
  <p>How do I remove the <strong>last character</strong> in the <code>JTextField</code>?</p>
  
  <pre><code>public void keyPressed (KeyEvent evt) {}
  public void keyReleased (KeyEvent evt) {
  
      int limit = 1;
      JTextField text = (JTextField)evt.getSource();
  
      if (text.getText().length() &gt;= limit) { 
          text.setEditable(false); 
      }
      else {
          if (evt.getKeyCode() == KeyEvent.VK_BACK_SPACE) {   
              answer ="";
              text.setEditable(true);
          }           
  
  public void keyTyped (KeyEvent evt) {}
  </code></pre>
  
  <p>}</p>