Using NetBeans IDE and Java, neither of which I'm overly familiar with. I have a JFrame laid out with a JPanel on it, and said JPanel has buttons on it. This JPanel is in the JFrames class. When one of these buttons is clicked, I would like to stop displaying this JPanel, and display another JPanel in a different class. I am using the GUI designer hence the panels being in different classes.
The buttonclick event in the JFrame class for one of the buttons I have:
private void buttonActionPerformed(ActionEvent e) {
panel1.setVisible(false);
Panel2 panel2 = new Panel2();
this.add(panel2);
panel2.setVisible(true);
This produces results of the panel1 disappearing however leaving a blank Jframe as panel2 does not display.
I have looked at CardLayout but I need the buttons on the panels to issue commands rather than buttons on another panel swapping around panels of a CardLayout.
EDIT: Have rewritten question to actually provide context and not just "help pls" as I've been told that what I was asking was too broad, which is completely correct. I've only just started learning Java so if this is still to broad aquestion, apologies.