title: Passing String from TextField To Another Class
body: <p>I want to pass the customer name to the class <code>StartSearchByName2</code>, I am using <code>netbeans IDE</code>. The customer name is got from the <code>Jtextfield</code>. 
  Please provide me some solution. I have basic knowledge about <code>Java</code>, and I am stuck with this for about 6 hours. </p>
  
  <p>Class StartSByName</p>
  
  <pre><code> public class StartSByName extends javax.swing.JFrame {
   String Customername;
    public void close() {
     WindowEvent winClosingEvent = new WindowEvent(this, WindowEvent.WINDOW_CLOSING);
      Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(winClosingEvent);
  }
  
  
       String NameM(String Name){
       Name = Customername;
       System.out.println(Name);
       return Name;
   }
  public StartSByName() {
      initComponents();
  }
  
  private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  jButtonAction5(evt);
  }                                                                                 
  public void jButtonAction5(ActionEvent evt) {
      Connection con = null;
      PreparedStatement st = null;
      ResultSet rs = null;
  
      try {
          Class.forName("com.mysql.jdbc.Driver");
          con=DriverManager.getConnection("jdbc:mysql://localhost:3306/holt", "root", "");
          st=con.prepareStatement("select * from customers where Name=?");
          Customername = jTextField1.getText();
          st.setString(1, Customername);
          rs = st.executeQuery();        
          jTextField1.setText(Customername);
          if (rs.next()) {
           JOptionPane.showMessageDialog(null, "Customer Found With ID = " + rs.getString("ID"));
            jTextField1.setText(Customername);
              String Name = null;
             NameM(Name);  // Calling NameM 
             StartSearchByName2 SB = new StartSearchByName2();
              SB.setVisible(true);
              close(); 
          } else {
              JOptionPane.showMessageDialog(null, "Customer Does Not Exist");
          }
      } catch (ClassNotFoundException | SQLException | HeadlessException ex) {
          System.out.println("Error " + ex);
      }   }
  </code></pre>
  
  <p>Class StartSearchByName2</p>
  
  <pre><code>public class StartSearchByName2 extends javax.swing.JFrame {
  String Name;
  StartSByName Sb= new StartSByName();
  public StartSearchByName2() {
      System.out.println(Sb.NameM(Name));
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>Tabish Raza // This Output from StartSByName Class and when calling NameM
  null // From StartSearchByName2, its twice null, but i called once and it is not giving me Correct String.
  null //
  </code></pre>