Where do you create a JPanel object for the panel variable?
Answer: You don't. So change this:
private JPanel panel;
to this:
private JPanel panel = new JPanel();
More importantly, you need to learn the general concepts of how to debug a NPE (NullPointerException). You should inspect the line carefully that throws it, find out which variable is null, and then trace back into your code to see why. You will run into these again and again, trust me.
As an aside: don't give your classes the same names as important core Java classes. For instance by naming your class GridLayout, you will now have trouble using the java.awt.GridLayout class without completely specifying the class name. You will thus want to change your class name to something else, say MyGridLayout
.