title: Passing jtextfield value from one class to another
body: <p>i have question regarding how to pass value of the jextfield from one frame to the jtextfield in the second frame upon click on a button.</p>
  
  <p>The example below, after inputting a value in the nett wage textfield, upon clicking the add button, the value will be passed on to the nett wage textfield of the second frame.</p>
  
  <p>Frame 1. I tried to add actionlistener to my button to get text, but how do i set it in the second frame? Appreciate if anyone can offer some advice and help.</p>
  
  <pre><code>public class Frame1 extends JFrame{
  public Frame1() {
  
      JPanel guiPanel = new JPanel(new GridBagLayout());
  
      JLabel Nett = new JLabel("Nett Wage: ");
      final JTextField nettNameTextField = new JTextField(10);
      JButton addButton = new JButton("Add");
  
  
      JPanel fields = new JPanel(new GridBagLayout());
  
      GridBagConstraints labelGBC = new GridBagConstraints();
      labelGBC.insets = new Insets(10, 3, 3, 3);
      GridBagConstraints fieldGBC = new GridBagConstraints();
      fieldGBC.insets = new Insets(10, 3, 3, 3);
      GridBagConstraints titleGBC = new GridBagConstraints();
      fieldGBC.gridwidth = GridBagConstraints.REMAINDER;
  
  
      fields.add(Nett, labelGBC);
      fields.add(nettNameTextField, fieldGBC);
  
  
      JPanel buttons = new JPanel(new GridBagLayout());
  
      GridBagConstraints addButtonGBC = new GridBagConstraints();
      addButtonGBC.insets = new Insets(40, 3, 3, 3);
      cancelButtonGBC.gridwidth = GridBagConstraints.REMAINDER;
      buttons.add(addButton, addButtonGBC);
  
  
      GridBagConstraints gbc = new GridBagConstraints();
      gbc.gridwidth = GridBagConstraints.REMAINDER;
      guiPanel.add(fields, gbc);
      guiPanel.add(buttons, gbc);
  
  
      add(guiPanel, BorderLayout.CENTER);
  
      /*addButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              String value = nettNameTextField.getText();
  
          }
      });*/
  </code></pre>
  
  <p>Frame 2. how do i go about setting the value in the textfield here?</p>
  
  <pre><code>public class Frame2 extends JFrame {
  public Frame2() {
  
  
      JPanel guiPanel = new JPanel(new GridBagLayout());
  
  
      JLabel nett = new JLabel("Nett Wage: ");
      JTextField nettNameTextField = new JTextField(10);
  
  
      JPanel fields = new JPanel(new GridBagLayout());
  
  
      GridBagConstraints labelGBC = new GridBagConstraints();
      labelGBC.insets = new Insets(10, 3, 3, 3);
      GridBagConstraints fieldGBC = new GridBagConstraints();
      fieldGBC.insets = new Insets(10, 3, 3, 3);
      //GridBagConstraints titleGBC = new GridBagConstraints();
      fieldGBC.gridwidth = GridBagConstraints.REMAINDER;
  
  
  
  
      JPanel savingspanel = new JPanel(new GridBagLayout());
  
      GridBagConstraints totallabelsGBC = new GridBagConstraints();
      totallabelsGBC.insets = new Insets(10, 3, 3, 3);
      GridBagConstraints totalfieldGBC = new GridBagConstraints();
      totalfieldGBC.insets = new Insets(10, 3, 3, 3);
      totalfieldGBC.gridwidth = GridBagConstraints.REMAINDER;
      savingspanel.add(nett, labelGBC);
      savingspanel.add(nettNameTextField, fieldGBC);
  
  
  
      add(guiPanel, BorderLayout.CENTER);                      
          }       
  }                 
  }
  </code></pre>