Is there a way to give a JButton an Action Listener that will change the contents of the JPanel the button is in (and deleting the button in the process). I have this code right now but it just makes the code freeze up.
public class CL extends Frame implements WindowListener, ActionListener
{
//Main method calls initializer (and sets size and visibility)
//Initializer adds a panel to the frame and a button that calls the action Listener
public void actionPerformed(ActionEvent event)
{
//Clear the JPanel (That the button is in)
panel.removeAll();
//Add new contents to the panel
JLabel label = new JLabel("This is a new label")
panel.add(label);
}
}
This doesn't throw any errors so... is there an error here or am I approaching this completely wrong? Thanks in advance for any help