title: How can I get a 2 second printing delay in a textarea between each letter/key that is pressed in another textarea?
body: <p>I'm trying to add a 2 second delay between each letter that is typed in one textarea before it is printed/displayed on another textarea.</p>
  
  <p>I've used two classes:</p>
  
  <ul>
  <li>One for a GUI called Printdelay</li>
  <li>One for the thread, called TwoSecondDelay</li>
  </ul>
  
  <p>Everything works fine except for the execution of the thread.</p>
  
  <p>Here's the code for the GUI:</p>
  
  <pre><code>import java.awt.event.KeyEvent;
  import java.awt.event.KeyListener;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  import javax.swing.JTextArea;
  
  
  public class PrintDelay extends javax.swing.JFrame implements KeyListener{
  
      int name;
  
      JTextArea server = new JTextArea (10, 20);
      JTextArea client = new JTextArea (10, 20);
  
  
      public PrintDelay () {
  
          super ("Typing...");
  
          setSize (650, 220);
          setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  
          JPanel panel = new JPanel ();
  
          server.addKeyListener (this);
  
          panel.add (server);
          panel.add (client);
          add(panel);
  
          setVisible (true);
  
      }
  
      public static void main (String... args) {
  
          new PrintDelay ();
  
      }
  
  
      @Override
      public void keyTyped(KeyEvent e)
      {
  
      }
  
      @Override
      public void keyPressed(KeyEvent e)
      {
  
      }
  
      @Override
      public void keyReleased(KeyEvent e)
      {
          new TwoSecondDelay (Integer.toString(name));
          name++;
          client.setText(server.getText());
      }
  
  }
  </code></pre>
  
  <p>Here's the code for the TwoSecondDelay:</p>
  
  <pre><code>public class TwoSecondDelay implements Runnable{
  
      String name;
      Thread t;
  
      TwoSecondDelay (String threadname) {
  
          name = threadname;
          t = new Thread (this, name);
          t.start();
  
      }
  
  
      @Override
      public void run() {
  
          try {
                  Thread.sleep(2000);
          } 
          catch (InterruptedException e) {
  
          }
  
      }
  
  }
  </code></pre>
  
  <p>Also the classes are in their own separate files.</p>