title: set gui contents from another class
body: <p>I want to be able to change the content of a some <code>JLabel</code> objects from another class. I have a <code>GUI</code> class containing all GUI objects (<code>JFrame</code>, <code>JPanel</code>, etc.). Let's say I have only one <code>JLabel</code>:</p>
  
  <pre><code>public class GUI {
      private JLabel label;
  
      public GUI() {
          initialize();//initializes all objects
      }
  
      public void update(String s) {
          this.label.setText(s);
      }
  }
  </code></pre>
  
  <p><code>GUI</code> has a public function <code>update(String)</code> that I hope to call from another class.</p>
  
  <p>My main class is called <code>App</code>:</p>
  
  <pre><code>public class App {
      private static GUI window;
  
      public static void main( String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try {
                      window = new GUI();
                      App.updateTxt("some string");
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
           });
      }
  
      public  static void updateTxt(String s) {
          window.update(s);
      }
  }
  </code></pre>
  
  <p>This solution does not work, however, <code>GUI.update(String)</code> is working perfectly when called inside the <code>GUI</code> class.
  I checked the solution proposed by Paul in:
  <a href="https://stackoverflow.com/questions/22833328/access-gui-components-from-another-class">Access GUI components from another class</a> but I did not understand it.
  So how can I invoke a method on <code>GUI</code> from another class to change the UI?</p>