title: Trying to refresh information in one class to another in java
body: <p>I have a class called A and a class called T. When A clicks a button I want it to update something T. I am having issues doing this... any advice thanks.</p>
  
  <p>Class A:</p>
  
  <pre><code>    FileWriter fstream = new FileWriter("open.txt", true);
      BufferedWriter out = new BufferedWriter(fstream);
      out.write("\n" +number1);
      jLabel1.setText(number1);
      out.close();
      T t = new T();
      t.refresh();
  </code></pre>
  
  <p>refresh is the function I want to be called to update class T</p>
  
  <p>T:</p>
  
  <pre><code>public void refresh() {
              File file = new File("open.txt");
      try {
  
          Scanner sc = new Scanner(file);
  
          if (sc.hasNext()) {
              jTextField2.setText(sc.next());
  
          } else {
              jTextField2.setText("Nothing to see here");
          }
      } catch (FileNotFoundException e) {
      e.printStackTrace();
  }
  </code></pre>
  
  <p>That's the function I want it to call. It just doesn't update the text. I figure it's something related to how I use the text file. Any ideas thanks.</p>