title: Two panels in one JFrame
body: <p>I know there have been many topics on this subject before and I have used Google extensively to figure this out, but whatever I do I cannot get two panels to display in one JFrame. I have tried many things including CardLayout but that didn't seem to work. I have a feeling this is a very easy solution..</p>
  
  <p>The purpose is to see the difference between the two panels due to the random positioning. </p>
  
  <p>Here are some of the java files (only pertinent code - there is also a Snowman.java but it just provides the drawing for the snowmen similar to ghost.java):</p>
  
  <p>Ghost.java</p>
  
  <pre><code>import java.awt.*;
  
  public class Ghost
  {
  private int x, y;
  private String name;
  private boolean happy;
  private Color color;
  
  public Ghost (Color shade, int upperX, int upperY, String a, boolean b)
  {
    color = shade;
    x = upperX;
    y = upperY;
    name = a;
    happy = b;
  }   
  
  public void draw (Graphics page)
  {
    page.setColor(color);
    page.fillOval (x, y, 50, 125);
    page.fillRect (x+1, y+60, 49, 75); // body of ghost
  
    page.setColor(Color.black);
    page.fillOval (x+12, y+10, 8, 8);
    page.fillOval (x+32, y+10, 8, 8); // eyes
  
    page.setColor(Color.white);
    page.drawString(name, x+8, y-5); // name
  
    page.setColor(Color.black);
    if (happy == true)
       page.fillArc  (x+10, y+30, 33, 10, 180, 180);
    else
       page.fillArc  (x+10, y+30, 33, 10, 0, 180); // smile/frown
  }     
  
  public void setColor (Color shade)
  {
    color = shade;
  }
  
  public void setX (int upperX)
  {
    x = upperX;
  }
  
  public void setY (int upperY)
  {
    y = upperY;
  }
  </code></pre>
  
  <p>HalloweenPanel.java :</p>
  
  <pre><code>import javax.swing.*;   
  import java.awt.*;
  import java.util.Random;
  
  public class HalloweenPanel extends JPanel
  {
   private Ghost ghost1, ghost2, ghost3;
   private Snowman snowman1, snowman2;
  
   public HalloweenPanel()
   {
    setBackground (Color.black);
  
    Random rand = new Random();
    int randomX = rand.nextInt(700)+50;
    int randomY = rand.nextInt(400)+50;
    boolean randomHappy = (Math.random() &lt; 0.5);
    boolean randomHappy2 = (Math.random() &lt; 0.5);
  
    ghost1 = new Ghost (Color.white, randomX, randomY, "Scary", randomHappy2);
    ghost2 = new Ghost (Color.blue, randomX, 100, "Happy", true);
    ghost3 = new Ghost (Color.yellow, 300, randomY, "Scared", randomHappy);
  
    snowman1 = new Snowman (500, 50);
    snowman2 = new Snowman (750, 100);  
    }
  
    public void paintComponent (Graphics page)
    {
    Random rand = new Random();
    int randomX2 = rand.nextInt(900);
    int randomY2 = rand.nextInt(500);
    super.paintComponent(page);
    ghost2.setX(randomX2);
    ghost3.setY(randomY2);
    ghost1.draw(page);
    ghost2.draw(page);
    ghost3.draw(page);
    snowman1.draw(page);
    snowman2.draw(page);
   }
  }
  </code></pre>
  
  <p>HalloweenDriver.java:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class HalloweenDriver
  {
  public static void main (String[] args)
   {
    JFrame frame = new JFrame ("Halloween - Winter is Coming..");
    frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
  
    JPanel mainPanel = new JPanel();
    HalloweenPanel panel = new HalloweenPanel();
    HalloweenPanel panel2 = new HalloweenPanel();
  
    mainPanel.setLayout(new GridLayout(1,0));
  
    mainPanel.add(panel);
    mainPanel.add(panel2);
  
    frame.add(mainPanel);
  
    frame.pack();
    frame.setVisible(true);
   }
  }   
  </code></pre>