GUI-Komponente in separate Klassen auslagern?

Hallo zusammen,

ich habe eine GUI programmiert. Leider ist der Code ziemlich unübersichtlich. Deswegen dachte ich, ich lagere die Erstellung der Komponenten aus. Nur leider verschwinden dann die ausgelagerten Komponenten aus der GUI.

Beispiel:

Erste Klasse:

package Verknüpfung;

import java.awt.BorderLayout;

public class Teil1 extends JFrame {
  private JPanel contentPane;

  static int f;

  /*
   * Launch the application.
   */
  public static void main(String[] args) {
    Teil2 blubb = new Teil2();
    Teil2.textfeld();

    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          Teil1 frame = new Teil1();
          frame.setVisible(true);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }

  /*
   * Create the frame.
   */
  public Teil1() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    JLabel lbl1 = new JLabel("Test");
    lbl1.setBounds(45, 68, 69, 20);
    contentPane.add(lbl1);

    JLabel lbl2 = new JLabel("Test");
    lbl2.setBounds(45, 151, 69, 20);
    contentPane.add(lbl2);
  
    JButton btnNewButton = new JButton("New button");
    btnNewButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent arg0) {
        int i;
        i = 5;
        f = i + 6;
      }
    });
    btnNewButton.setBounds(209, 199, 115, 29);
    contentPane.add(btnNewButton);
  }
}

Zweite Klasse:

package Verknüpfung;

import java.awt.BorderLayout;

public class Teil2 extends JFrame {
  private JPanel contentPane;

  private JTextField txt1;

  private JTextField txt2;

  /*
   * Launch the application.
   */
  public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
        try {
          Teil2 frame = new Teil2();
          frame.setVisible(true);
        }
        catch (Exception e) {
          e.printStackTrace();
        }
      }
    });
  }
                                                                                                  
  /*
   * Create the frame.
   */
  public Teil2() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);

    txt1 = new JTextField();
    txt1.setBounds(267, 74, 146, 26);
    contentPane.add(txt1);
    txt1.setColumns(10);
    
    txt2 = new JTextField();
    txt2.setBounds(267, 149, 146, 26);
    contentPane.add(txt2);
    txt2.setColumns(10);
    txt2.setText("Hi");
  }

  public static void textfeld() {
  }                                                                               }

programmieren, Java, Oberfläche, GUI