title: JTextfield KeyListener, generate string when enter key is pressed
body: <p>i have created a simple Java chat with a simple GUI, and i would like to add the option that when the ENTER key is pressed, the text that was entered in the Jtextfield would be inserted into a String variable.
  For some reason it doesn't work</p>
  
  <p>The code is below:</p>
  
  <pre><code>  txt.addKeyListener(new KeyAdapter(){
          public void keyTyped(KeyEvent e) {
              if( e.getKeyCode() == KeyEvent.VK_ENTER ){  
                  String message_2send = txt.getText();
                  Sendmsg(message_2send,cuser);}}});
  </code></pre>
  
  <p>Please assist.</p>