title: Can not set text for JTextField from another class
body: <p>I have ran into yet another issue. I am trying to set the text of a JTextField from another java class, and it does not seem to work. </p>
  
  <p>I have tried the following:</p>
  
  <ul>
  <li>calling the setter from inside the GUI class to .setText with a String. WORKS!</li>
  <li>Setting the JTextField to some text so it isnt NULL -failed </li>
  <li>Calling another method inside the GUI class, pass the string, then call the setter for the JTextField to set its text to the string. -failed (Just an idea i wanted to play with) </li>
  <li>I did insure that the string is passed into the setter method by using a println. WORKED. </li>
  </ul>
  
  <p>From googling around I believe that i have not set the reference to the main GUI? </p>
  
  <p>Here is the GUI Class:</p>
  
  <pre><code>package book;
  
  import book.BookIO;
  import java.awt.BorderLayout;
  import java.awt.*;
  import javax.swing.*;
  import java.awt.GridBagLayout;
  import java.awt.GridBagConstraints;
  import java.awt.Insets;
  import java.awt.event.ActionListener;
  import java.awt.event.ActionEvent;
  
  /**
   *
   * 
   */
  public class UserInterface implements ActionListener {
  
      //Containers 
  
      JFrame frame = new JFrame("Ye old Book stoppe");
      JPanel toppane = new JPanel(new GridBagLayout());
      JPanel bottomPane = new JPanel(new GridBagLayout());
      //Buttons
      JButton processItem = new JButton("Process Item #1");
      JButton confirmItem = new JButton("Confirm Item #1");
      JButton viewOrder = new JButton("View Order");
      JButton finishOrder = new JButton("Finish Order ");
      JButton newOrder = new JButton("New Order");
      JButton exit = new JButton("Exit");
      //TextFields
      JTextField amount = new JTextField();
      JTextField id = new JTextField();
      JTextField quantity = new JTextField();
      JTextField info = new JTextField("");
      JTextField total = new JTextField();
      //Labels
      JLabel num = new JLabel("Enter Number of Items in this Order:");
      JLabel bookID = new JLabel("Enter Book ID for Item #1:");
      JLabel quantityItem = new JLabel("Enter Quantity for Item #1:");
      JLabel itemInfo = new JLabel("Item #1:");
      JLabel subtotal = new JLabel("Order subtotal for 0 Items(s):");
  
      public void startUI() {
  
          UserInterface gui = new UserInterface();
          gui.bookingUI();
  
      }
  
      public void bookingUI() {
          //sets windows, and pane in the UI 
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          GridBagConstraints c = new GridBagConstraints();
          frame.setSize(800, 300);
  
          //adding the labels to the panel
          c.insets = new Insets(5, 0, 0, 0);
          c.gridx = 2;
          c.gridy = 1;
          toppane.add(num, c);
          c.gridx = 2;
          c.gridy = 2;
          toppane.add(bookID, c);
          c.gridx = 2;
          c.gridy = 3;
          toppane.add(quantityItem, c);
          c.gridx = 2;
          c.gridy = 4;
          toppane.add(itemInfo, c);
          c.gridx = 2;
          c.gridy = 5;
          toppane.add(subtotal, c);
          toppane.setBackground(Color.GREEN);
          frame.add(toppane);
  
          //add textfield to panel
          c.ipadx = 400;
          c.insets = new Insets(5, 10, 0, 0);
          c.gridx = 3;
          c.gridy = 1;
          toppane.add(amount, c);
          c.gridx = 3;
          c.gridy = 2;
          toppane.add(id, c);
          c.gridx = 3;
          c.gridy = 3;
          toppane.add(quantity, c);
          c.gridx = 3;
          c.gridy = 4;
          toppane.add(info, c);
          c.gridx = 3;
          c.gridy = 5;
          toppane.add(total, c);
  
          //----------------------------------------------------------BUTTOM PANE-------------------------
          //adding the buttons to the pane.---------------------------------------------------------------
          GridBagConstraints b = new GridBagConstraints();
          b.insets = new Insets(5, 5, 5, 5);
          b.ipadx = 10;
          b.ipady = 10;
          b.gridx = 1;
          b.gridy = 0;
          bottomPane.add(processItem, b);
          processItem.addActionListener(this);
          b.gridx = 2;
          b.gridy = 0;
          bottomPane.add(confirmItem, b);
          confirmItem.setEnabled(false);
          confirmItem.addActionListener(this);
          b.gridx = 3;
          b.gridy = 0;
          bottomPane.add(viewOrder, b);
          viewOrder.setEnabled(true);
          viewOrder.addActionListener(this);
          b.gridx = 4;
          b.gridy = 0;
          bottomPane.add(finishOrder, b);
          finishOrder.setEnabled(true);
          finishOrder.addActionListener(this);
          b.gridx = 5;
          b.gridy = 0;
          bottomPane.add(newOrder, b);
          newOrder.addActionListener(this);
          b.gridx = 6;
          b.gridy = 0;
          bottomPane.add(exit, b);
          exit.addActionListener(this);
          bottomPane.setBackground(Color.BLUE);
          frame.add(bottomPane, BorderLayout.SOUTH);
          frame.setSize(810, 310);
          frame.setVisible(true);
      }
  
      //action listener for the buttons 
      public void actionPerformed(ActionEvent e) {
  
          if (e.getSource() == processItem) {
              confirmItem.setEnabled(true);
              processItem.setEnabled(false);
              BookIO findInfo = new BookIO();
              findInfo.readFile(id.getText());
  
          } else if (e.getSource() == confirmItem) {
              processItem.setEnabled(true);
              confirmItem.setEnabled(false);
          } else if (e.getSource() == viewOrder) {
  
          } else if (e.getSource() == finishOrder) {
  
          } else if (e.getSource() == newOrder) {
  
          } else if (e.getSource() == exit) {
              System.exit(0);
          }
      }
  
  //Creating getters and setters to change the text for the buttons and labels, as well as getting text from the textfields.
      public void setProcessItemBtn(int num) {
          processItem.setText("Process Item #" + num);
          processItem.validate();
          processItem.repaint();
      }
  
      public void setConfirmItemBtn(int num) {
          confirmItem.setText("Confirm Item #" + num);
          confirmItem.validate();
          confirmItem.repaint();
      }
  
      public void setViewOrderBtn(String title) {
  
          viewOrder.validate();
          viewOrder.repaint();
      }
  
      public void setInfo(String title) {
          System.out.println(title);
          info.setText(title);
          info.validate();
          info.repaint();
      }
  
      public String getAmount() {
          String str = amount.getText();
          return str;
      }
  }
  </code></pre>
  
  <p>Here is the class with the method call to the setter:</p>
  
  <pre><code>package book;
  
  import book.UserInterface;
  import java.io.BufferedReader;
  import java.io.FileReader;
  import java.io.IOException;
  import java.util.Objects;
  import java.util.StringTokenizer;
  
  /**
   *
   * 
   */
  public class BookIO {
  
      public void readFile(String bookID) {
  
          try {
  
              FileReader read = new FileReader("inventory.txt");
              BufferedReader buffer = new BufferedReader(read);
              StringBuffer stringBuff = new StringBuffer();
              String line, delim = "[,]";
              for (int i = 0; i &lt; 12; i++) {
                  line = buffer.readLine();
                  String[] tokens = line.split(delim);
  
                  if ((Objects.equals(tokens[0], bookID)) == true) {
                      UserInterface setInfo = new UserInterface();
                      setInfo.setInfo(tokens[1]);
                  }
              }
  
          } catch (IOException e) {
              System.out.println("Error starting file!");
          }
      }
  
  }
  </code></pre>