title: After creating JTextField dynamically, how do i use getText()?
body: <p>I have referred to this <a href="https://stackoverflow.com/questions/5098017/i-want-to-add-a-jlabel-and-text-box-dynamically-by-clicking-add-button">I want to add a JLabel and Text box dynamically by clicking add button</a> to create my <code>JTextField</code> dynamically.</p>
  
  <p>But how do i use the <code>getText()</code> to retrieve the text from each of the textfields individually?</p>
  
  <pre><code>public class CreateGuestForm2 {
  
  private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="111,10"
  private JPanel jContentPane = null;
  private int indexer = 1;  //  @jve:decl-index=0:
  private List&lt;JLabel&gt; listOfLabels = new ArrayList&lt;JLabel&gt;();  //  @jve:decl-index=0:
  private List&lt;JTextField&gt; listOfTextFields = new ArrayList&lt;JTextField&gt;();  //  @jve:decl-index=0:
  private JButton jButtonAdd = null;
  private JPanel jPanel = null;
  private GridBagConstraints textFieldConstraints = new GridBagConstraints();  //  @jve:decl-index=0:
  private GridBagConstraints labelConstraints = new GridBagConstraints();//  @jve:decl-index=0:
  private JButton jButtonCreate = null;
  private JButton jButtonHelp = null;
  String textFields = null;
  
  
  
  /**
   * This method initializes jFrame   
   *  
   * @return javax.swing.JFrame   
   */
  private JFrame getJFrame() {
      if (jFrame == null) {
          jFrame = new JFrame();
          jFrame.setLayout(new GridBagLayout());
          jFrame.setPreferredSize(new Dimension(800, 600));
          jFrame.setTitle("Create Guest Form");
          jFrame.setSize(new Dimension(800, 582));
          jFrame.setContentPane(getJContentPane());
          jFrame.pack();
          jFrame.setVisible(true);
      }
      return jFrame;
  }
  
  
  /**
   * This method initializes jContentPane 
   *  
   * @return javax.swing.JPanel   
   */
  private JPanel getJContentPane() {
      if (jContentPane == null) {
          jContentPane = new JPanel();
          jContentPane.setLayout(null);
          jContentPane.add(getJButtonAdd(), null);
          jContentPane.add(getJPanel(), null);
          jContentPane.add(getJButtonCreate(), null);
          jContentPane.add(getJButtonHelp(), null);
          jContentPane.add(getJPanel(), null);
          jContentPane.add(getJPanel(), null);
      }
      return jContentPane;
  }
  
  
  /**
   * This method initializes jButtonAdd   
   *  
   * @return javax.swing.JButton  
   */
  private JButton getJButtonAdd() {
      if (jButtonAdd == null) {
          jButtonAdd = new JButton();
          jButtonAdd.setText("Add a guest");
          jButtonAdd.setBounds(new Rectangle(14, 45, 111, 24));
          jButtonAdd.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent e) {
                  System.out.println("actionPerformed()"); 
                  addGuest(e);
              }
          });
      }
      return jButtonAdd;
  }
  
  public void addGuest(ActionEvent e){
      // Clear panel
      jPanel.removeAll();
  
      // Create label and text field
      JTextField jTextField = new JTextField();
      textFields = jTextField.getText();
      jTextField.setSize(100, 200);
      listOfTextFields.add(jTextField);
      listOfLabels.add(new JLabel("Guest " + indexer));
  
      // Add labels and text fields
      for(int i = 0; i &lt; indexer; i++)
      {
          // Text field constraints
          textFieldConstraints.gridx = 1;
          textFieldConstraints.fill = GridBagConstraints.HORIZONTAL;
          textFieldConstraints.weightx = 0.5;
          textFieldConstraints.insets = new Insets(10, 10, 10, 10);
          textFieldConstraints.gridy = i;
  
          // Label constraints
          labelConstraints.gridx = 0;
          labelConstraints.gridy = i;
          labelConstraints.insets = new Insets(10, 10, 10, 10);
  
          // Add them to panel
          jPanel.add(listOfLabels.get(i), labelConstraints);
          jPanel.add(listOfTextFields.get(i), textFieldConstraints);
  
  
      }
  
      // Align components top-to-bottom
      GridBagConstraints c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = indexer;
      c.weighty = 1;
      jPanel.add(new JLabel(), c);
      indexer++;
      jPanel.updateUI();
  }
  /**
   * This method initializes jPanel   
   *  
   * @return javax.swing.JPanel   
   */
  private JPanel getJPanel() {
      if (jPanel == null) {
          jPanel = new JPanel();
          jPanel.setLayout(new GridBagLayout());
          jPanel.setPreferredSize(new Dimension(600,600));
          jPanel.setBounds(new Rectangle(14, 76, 759, 413));
          jPanel.setBorder(LineBorder.createBlackLineBorder());
  
  
      }
      return jPanel;
  }
  
  /**
   * This method initializes jButtonCreate    
   *  
   * @return javax.swing.JButton  
   */
  private JButton getJButtonCreate() {
      if (jButtonCreate == null) {
          jButtonCreate = new JButton();
          jButtonCreate.setText("Create");
          jButtonCreate.setBounds(new Rectangle(681, 505, 93, 27));
          jButtonCreate.addActionListener(new java.awt.event.ActionListener() {
              public void actionPerformed(java.awt.event.ActionEvent e) {
                  System.out.println("actionPerformed()"); // TODO Auto-generated Event stub actionPerformed()
                  createGuest(e);
              }
          });
      }
      return jButtonCreate;
  }
  
  public void createGuest(ActionEvent e){
      String record = textFields;
      GuestControl gCreate = new GuestControl();
      if(gCreate.processCreateGuest2(record)){
          JOptionPane.showMessageDialog(null, "Guest record created successfully");
          getJFrame().dispose();
      }
      else
      {
              JOptionPane.showMessageDialog(null, "Guest not created, please try again");
  
      }
  
  }
  }
  </code></pre>
  
  <p>ps: i am doing this for a school project on creating a guest form</p>