title: How can I pass variables from a jtextfield to another one in another JFrame/class?
body: <p>I've got a problem with JTextField. I don't know how to pass a variable from a JTextField (situated in JFrame A) to another JTextField (situated in JFrame B). 
  I tried to do that, but it doesn't do anything, i.e. it doesn't get any runtime/compilation error nor it receives the text.</p>
  
  <p>I tried to do this in ClassB:</p>
  
  <pre><code>ClassA a = new ClassA();
  String text = a.jtextfield1.getText();
  </code></pre>
  
  <p>but it doesn't work!!</p>
  
  <p>Could you help me, may with a simple example? What did I do wrong? </p>
  
  <p>p.s.: i'm using netbeans</p>
  
  <p>[edit --] That's the code of ClassA:</p>
  
  <pre><code>public class ClassA extends javax.swing.JFrame {
  
  public ClassA() {
      initComponents();
  }
  
  public void initComponents() {
  
      jTextField1 = new javax.swing.JTextField();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      jTextField1.setText("Some text blah blah");
      jTextField1.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              jTextField1ActionPerformed(evt);
          }
      });
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(33, 33, 33)
              .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 104, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(124, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(47, 47, 47)
              .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addContainerGap(86, Short.MAX_VALUE))
      );
  
      pack();
  }
  
  public static void main(String args[]) {
  
      java.awt.EventQueue.invokeLater(new Runnable() {
  
          public void run() {
              new ClassA().setVisible(true);
          }
      });
  }
  
  public javax.swing.JTextField jTextField1;
  </code></pre>
  
  <p>}</p>
  
  <p>Here's the code of ClassB: </p>
  
  <pre><code>public class ClassB extends javax.swing.JFrame {
  
  public ClassB() {
      initComponents();
  }
  
    public  ClassA a = new ClassA();
  
  
  public void initComponents() {
  
      jTextField1 = new javax.swing.JTextField();
      getText = new javax.swing.JButton();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
      getText.setText("GetText");
      getText.addActionListener(new java.awt.event.ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent evt) {
              getTextActionPerformed(evt);
          }
      });
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addGap(31, 31, 31)
                      .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 114, javax.swing.GroupLayout.PREFERRED_SIZE))
                  .addGroup(layout.createSequentialGroup()
                      .addGap(50, 50, 50)
                      .addComponent(getText)))
              .addContainerGap(143, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
              .addGap(50, 50, 50)
              .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
              .addGap(26, 26, 26)
              .addComponent(getText)
              .addContainerGap(49, Short.MAX_VALUE))
      );
  
      pack();
  }
  
  public void getTextActionPerformed(java.awt.event.ActionEvent evt) {
      a.jTextField1.getText(); //this doesn't work. How can I it makes work?
  }
  
  public static void main(String args[]) {
  
      java.awt.EventQueue.invokeLater(new Runnable() {
  
          public void run() {
              new ClassB().setVisible(true);
          }
      });
  }
  
  public javax.swing.JButton getText;
  public javax.swing.JTextField jTextField1;
  </code></pre>
  
  <p>}</p>
  
  <p>Thanks in advance. </p>