java gui removing a label using JButton
<p>What i need some help with is removing a label and creating a new one with a button click. At the moment this will add a new label but won't remove the old. I can't find a command that will work, northpanel.remove() will destroy the panel and the previous label, but then i can't create any new ones.</p>

<pre><code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

@SuppressWarnings("serial")
public class test2 extends JFrame implements ActionListener {

 private JTextField textfield;

 private JPanel northPanel = new JPanel();
 private JPanel southPanel = new JPanel();

 public test2() {
  setSize(400, 200);

  BorderLayout layout = new BorderLayout ();
  setLayout(layout);

  JLabel label1 = new JLabel("remove this");
  northPanel.add(label1);

  JLabel label2 = new JLabel("Enter move");
  southPanel.add(label2);
  textfield = new JTextField(10);
  southPanel.add(textfield);
  JButton button = new JButton("Move / remove label");
  button.addActionListener(this);
  southPanel.add(button);

  add(northPanel, BorderLayout.NORTH);
  add(southPanel, BorderLayout.SOUTH);
 }

 @Override
 public void actionPerformed(ActionEvent e) {
  String text = textfield.getText();

  if (text.equals("")) {
   System.out.println("textfield is empty");
  } else {
   System.out.println(text);
  }


 // northPanel.remove();

  JLabel label3 = new JLabel("new label");
  northPanel.add(label3);

  repaint();
  validate();
 }

 public static void main(String[] args) {
  test2 app = new test2();
  app.setVisible(true);
  app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 }
}
</code></pre>
