title: Accessing Swing-Components from another class
body: <p>I have got a Java-Swing-GUI with a structure like this:<br />
  JFrame<br />
  -- JPanel1<br />
  -----jButton1<br />
  -----jLabel1<br /></p>
  
  <p>My target is that when jButton1 is pressed I want to change the color of jLabel1 or set some text onto it, but this should be done in an external class (let's call it externalClass).</p>
  
  <p>So in the constructor of the GUI-class I pass itself to my external class:</p>
  
  <pre><code>public class GUIclass extends javax.swing.JFrame {  
      private externalClass e;
      public GUIclass() {
          initComponents();
          e = new externalClass(GUIclass.this);
  }
  </code></pre>
  
  <p>In my external class I am not able to access e.g. the label:</p>
  
  <pre><code>private GUIclass g;
  public externalClass(GUIclass g) {
      this.g = g;
      System.out.println(g.getComponentCount());
          // --&gt; only 1, is this the JFrame (?)
      System.out.println(g.getComponent(0).getName());
          // always "null"
  }
  </code></pre>
  
  <p>Could anybody please explain to me how I could get access to the label?
  Also I am worried why the name of the component is always "null".</p>
  
  <p>Thanks in advance!</p>