title: Write the value of a JTextField to a variable of type String from another class (JAVA)
body: <p>I am very difficult to record the value typed into a JTextField that belongs to class 1 in variable of type String that belongs to class 2, for example, if I type the word "Test" in the JTextField class 1 when i press the button in class 1, I would like the value entered in the JTextField class 1 is recorded on a variable type String in class 2, so I use this variable as I want, can you give me a hand with that? I've tried to create an object of class 1 and use the getText and to String, but no success yet. When i see the System in the class2 the result is NULL ! :(</p>
  
  <p>Thank you. </p>
  
  <p>The code :</p>
  
  <pre><code>public class Class1 extends javax.swing.JFrame {
  
      public Class1() {    
          initComponents();    
      }    
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  
      private void initComponents() {
          fieldOfClass1 = new javax.swing.JTextField();    
          bottonOfClass1 = new javax.swing.JButton();    
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);    
          getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());    
          getContentPane().add(fieldOfClass1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 39, 336, 38));    
          bottonOfClass1.setText("Botton");    
          bottonOfClass1.addActionListener(new java.awt.event.ActionListener() {
  
              public void actionPerformed(java.awt.event.ActionEvent evt) {    
                  bottonActionPerformed(evt);    
              }    
          });
  
          getContentPane().add(bottonOfClass1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 114, 161, 45));
          pack();
  
      }// &lt;/editor-fold&gt;  
      private void bottonActionPerformed(java.awt.event.ActionEvent evt) {                                       
  
  Class2 classTwo = new Class2();
  
      classTwo.receiveFieldValueOfClass1= returnField();
          System.out.println(classTwo.receiveFieldValueOfClass1);
      } 
  
      String returnField(){    
        return fieldOfClass1.getText().toString();
      }    
  
      public static void main(String args[]) {
           new Class1().setVisible(true);
      }
  
      // Variables declaration - do not modify  
      private javax.swing.JButton bottonOfClass1;
      private javax.swing.JTextField fieldOfClass1;
      // End of variables declaration
  }
  </code></pre>
  
  <p>Class 2 :</p>
  
  <pre><code>public class Class2 {
  
      public String receiveFieldValueOfClass1;
  
      Class2(){
          System.out.println("This is a valor of Jtext Field Class 1 ! = "+receiveFieldValueOfClass1);
      } 
  
      public static void main (String[]args){         
  
      }
  }
  </code></pre>
  
  <p>Thanks </p>