title: Exception in thread "main" java.lang.IllegalArgumentException: cannot add to layout: constraints must be a GridBagConstraint
body: <p>Im righting a simple text based game for my computing coursework but I'm having a few problems grasping how to use the AWT <code>GridBagLayout</code> and <code>GridBagConstraints</code>. </p>
  
  <p>When ever I run the code i get this error message:</p>
  
  <p><img src="https://i.stack.imgur.com/lR9JM.png" alt="enter image description here"></p>
  
  <p>Here is a copy of my GUI code:</p>
  
  <pre><code>import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JScrollPane;
  import javax.swing.JTextArea;
  
  import java.awt.Dimension;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.Toolkit;
  import java.awt.*;
  @SuppressWarnings("unused")
  
  public class GUI extends JFrame
  {
  
      public void main(String[] args)
      {
          new GUI();
      }
  
      public GUI()
      {
  
          JFrame AG = new JFrame("Adventure Game");
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  
          setBounds(0, 0, screenSize.width, screenSize.height);
          setResizable(true);
          setVisible(true);
          setDefaultCloseOperation(EXIT_ON_CLOSE);
  
          JPanel p=new JPanel();
          p.setLayout (new GridBagLayout());
  
          AG.add(p);
          GridBagConstraints GBC = new GridBagConstraints();
          AG.getContentPane().add(p, BorderLayout.NORTH);
  
          JButton saveButton =new JButton("Save");
          JButton loadButton =new JButton("Load");
          JButton optionsButton = new JButton("Options");
  
          JLabel textBox= new JLabel("Story line will go here.");
  
          JLabel label11 = new JLabel("Test 1");
          GBC.gridx = 0;
          GBC.gridy = 1;
          p.add(label11,AG);
          JLabel label12 = new JLabel("Test 2");
          GBC.gridx = 0;
          GBC.gridy = 2;
          p.add(label12,AG);
          JLabel label13 = new JLabel("Test 3");
          GBC.gridx = 0;
          GBC.gridy = 3;
          p.add(label13,AG);
          JLabel label14 = new JLabel("Test 4");
          GBC.gridx = 0;
          GBC.gridy = 4;
          p.add(label14,AG);
  
          add(p);
      }
  }
  </code></pre>
  
  <p>I think the problem is me trying to use <code>GridBagConstraints</code> without using <code>GridBagLayout</code> but I'm quite new to java so don't how to use <code>GridBagLayout</code> to fix the problem, most of this code is from various different tutorials I've watched on youtube, but not copied just taking how various people do it and trying to mix it badly</p>
  
  <p>Thanks for the help
  - Tom</p>