title: Pass a JPanel class to the main class in JAVA
body: <p>I need to pass a JPanel extending class to the main class.</p>
  
  <p>Here is what I have so far:
  Main class</p>
  
  <pre><code>import java.awt.Color;
  import javax.swing.*;
  
  public class main {
  
      private gamePanel gamepanel = new gamePanel();
  
      public JPanel createContentPane(){
          // We create a bottom JPanel to place everything on.
          JPanel totalGUI = new JPanel();
  
          //We set the Layout Manager to null so we can manually place
          // the Panels.
          totalGUI.setLayout(null);
  
          //Now we create a new panel and add it to the bottom JPanel.
  
          totalGUI.add(gamepanel);
  
  
  
          totalGUI.setOpaque(true);
          return totalGUI;
      }
  
      private static void createAndShowGUI(){
          JFrame.setDefaultLookAndFeelDecorated(true);
          JFrame frame = new JFrame("[=] There's a JPanel in here! [=]");
  
          //Create and set up the content pane.
          main demo = new main();
          frame.setContentPane(demo.createContentPane());
  
          //The other bits and pieces that make your program a bit more stable.
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setSize(700,500);
          frame.setVisible(true);
  
      }
      public static void main(String[] args) {
          //Schedule a jog for the event-dispatching thread:
          //creating and showing this application's GUI.
          System.out.println(gamepanel);
          SwingUtilities.invokeLater(new Runnable() {
              public void run(){
                  createAndShowGUI();
              }
          });
      }
  }
  </code></pre>
  
  <p>The gamePanel class</p>
  
  <pre><code>public class gamePanel extends JPanel implements Commons {
  
      private Dimension d;
      private ArrayList snowmens;
      private coreFunctions functions = new coreFunctions();
      private int snowmenX = 150;
      private int snowmenY = 5;
      private final String snowmenpix = "snowman.png";
      private JPanel background;
  
  public gamePanel() {
  
  
  
      add(new JLabel("TEST"));
      setFocusable(true);
  
  
      setDoubleBuffered(true);
  }
  
  
  @Override
  public void paintComponent(Graphics g) {
      super.paintComponent(g);
      g.setColor(Color.BLUE);
      g.fillRect(0, 0, 700, 700);
  
  
  
  }
  }
  </code></pre>
  
  <p>I can't figure out why the blue background and the label is not being shown...</p>
  
  <p>EDIT:</p>
  
  <p>Here are more details:</p>
  
  <p>Ok so I am trying to make a little 2D game. For that I need to create some snowmen on the gamePanel class and display it via the main class. To start it off, the createContentPane creates a background panel, the root panel if you want. The createandshowgui creates a JFrame.</p>
  
  <p>The gamepanel class is in fact a JPanel which has 1 panel as of now, which is the background panel. For now, I only want it to have a blue background.</p>
  
  <p>I tried putting it like this because I saw some examples and they were pretty similar to what I have, but for some reason, I can't get it to work....</p>
  
  <p>Thank you,
  Ara</p>