title: Convert Java program with TextField to swing JTextField
body: <p>This piece of code is a simplified version of a program I would convert to swing (using <code>JTextField</code> and <code>DocumentListener</code>). I have read some tutorials but I can't do it...
  I shouldn't use global variables and I have to use some like <code>getSource()</code> (<code>getDocument()</code> in this case?), because in the original program the number of JTextField is variable (they are generated inside a <code>for</code>, so they haven't a "name"). This number depends on a value written in a text file.</p>
  
  <pre><code>import java.awt.*;
  import java.awt.event.*;
  
  class TestWindow extends Frame {
      public TestWindow() {
          Panel p = new Panel(new FlowLayout());
          Label l = new Label("Temp");
          TextField tf1 = new TextField();
          TextField tf2 = new TextField();
          tf1.addTextListener(new myTextListener(l));
          tf2.addTextListener(new myTextListener(l));
          p.add(tf1);
          p.add(tf2);
          tf1.setColumns(10);
          tf2.setColumns(10);
          p.add(l);
          add(p);
          pack();
          setVisible(true);
      }
  
      class myTextListener implements TextListener {
          Label input;
          myTextListener(Label input) {
              this.input = input;
          }
          public void textValueChanged(TextEvent e) {
              input.setText(((TextField)(e.getSource())).getText());
          }
      }
  
  }
  
  public class Test {
  
      public static void main(String[] args) {
          new TestWindow();
      }
  
  }
  </code></pre>