In the following code I am trying to design a full screen menu. To do this I thought it would be best to use two JPanels. My problem is when trying to switch between the JPanels I get a java.lang.NullPointerException. The exception states that it occurs on line 101 which is this line. m.getMainWindow().getContentPane().setComponentZOrder(m.getOverlay(), 0); Originally I believed to problem to be an instance problem; however, upon passing the menu variable, which is used in the main void at the end of the public class Menu, though all the relevant methods the null pointer still occurs. I would appreciate any help in fixing my problem.
Code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import net.miginfocom.swing.MigLayout;
public class Menu {
    JFrame myMainWindow = new JFrame("Menu test");
    GridBagConstraints c;
    JLayeredPane lP;
    MyFirstPanel fP;
    MyOverlay oL;
    MigLayout baseLayout;
    MigLayout overlayLayout;
    private void runGUI(Menu m) {       
        myMainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myMainWindow.setLayout(new GridBagLayout());
        setContraints();
        createPanels(m);
        myMainWindow.getContentPane().add(fP, c);
        myMainWindow.getContentPane().add(oL, c);
        myMainWindow.pack();
        myMainWindow.setVisible(true);
    }
    private void setContraints() {
        c = new GridBagConstraints();
        c.gridx = 0;
        c.gridy = 0;
        c.weightx = 1;
        c.weighty = 1;
        c.fill = GridBagConstraints.BOTH;
    }
    private void createPanels(Menu m) {
        createFirstPanel(m);
        createOverlay();
    }
    private void createFirstPanel(Menu m) {
        baseLayout = new MigLayout("", "", "");
        fP = new MyFirstPanel(baseLayout, m);
    }
    private void createOverlay() {
        overlayLayout = new MigLayout("", "", "");
        oL = new MyOverlay(overlayLayout, true);
    }
    public JPanel getOverlay() {
        return oL;
    }
    public JFrame getMainWindow() {
        return myMainWindow;
    }
    public static void main(String[] args) {
        Menu menu = new Menu();
        menu.runGUI(menu);
    }
}
class MyFirstPanel extends JPanel {
    MyFirstPanel(MigLayout layout, Menu mM) {
        setLayout(layout);
        setBackground(Color.RED);
        setPreferredSize(new Dimension(600, 600));
        add(new JLabel("hiasdfadsf"), "wrap");
        JButton jb = new JButton("Press Me");
        jb.addActionListener(new CustomActionListener(mM));
        add(jb);
    }
}
class MyOverlay extends JPanel {
    MyOverlay(MigLayout layout, boolean visible) {
        setBackground(Color.GREEN);
        setPreferredSize(new Dimension(600, 600));
        add(new JLabel("hi"));
        setVisible(visible);
    }
}
class CustomActionListener implements ActionListener {
    Menu m;
    public CustomActionListener(Menu mM) {
        this.m = mM;
        m.getMainWindow().getContentPane().setComponentZOrder(m.getOverlay(), 0);
    }
    public void actionPerformed(ActionEvent e) {
        m.getMainWindow().getContentPane().setComponentZOrder(m.getOverlay(), 0);
    }
}
Exception
Exception in thread "main" java.lang.NullPointerException
    at java.awt.Container.setComponentZOrder(Container.java:760)
    at packages.CustomActionListener.<init>(Menu.java:101)
    at packages.MyFirstPanel.<init>(Menu.java:75)
    at packages.Menu.createFirstPanel(Menu.java:44)
    at packages.Menu.createPanels(Menu.java:38)
    at packages.Menu.runGUI(Menu.java:21)
    at packages.Menu.main(Menu.java:64)
 
    