I am getting the following error...

Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
        at java.awt.Container.addImpl(Container.java:1010)
        at java.awt.Container.add(Container.java:928)
        at javax.swing.JFrame.addImpl(JFrame.java:480)
        at java.awt.Container.add(Container.java:899)
        at BoardCreator.<init>(BoardCreator.java:40)
        at Board.main(Board.java:14)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)

Here is my code which is a box that someone who would want to buy a skateboard would check off and the price would be displyed...

import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class DeckPanel extends JFrame

   private final double MASTERTHRASHER = 60.00;
   private final double DICTATOR = 45.00;
   private final double STREETKING = 50.00;

   private JRadioButton masterThrasher;
   private JRadioButton dictator;
   private JRadioButton streetKing;

   public DeckPanel()
       setLayout(new GridLayout(3,1));

       masterThrasher = new JRadioButton("The Master Thrasher: $60");
       dictator = new JRadioButton("The Dictator");
       streetKing = new JRadioButton("The Street King");


   public double getDeckCost()
       double deckCost = 0;

       if (masterThrasher.isSelected())
           deckCost = MASTERTHRASHER;
       if (dictator.isSelected())
           deckCost = DICTATOR;
       if (streetKing.isSelected())
           deckCost = STREETKING;
       return deckCost;


import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class TruckPanel extends JFrame

   private final double TRUCK1 = 35.00;
   private final double TRUCK2 = 40.00;
   private final double TRUCK3 = 45.00;

   private JRadioButton truck1;
   private JRadioButton truck2;
   private JRadioButton truck3;

   public TruckPanel()
       setLayout(new GridLayout(3,1));

       truck1 = new JRadioButton("7.75 in axle");
       truck2 = new JRadioButton("8 in axle");
       truck3 = new JRadioButton("8.5 in axle");


   public double getTruckCost()
       double truckCost = 0;

       if (truck1.isSelected())
           truckCost = TRUCK1;
       if (truck2.isSelected())
           truckCost = TRUCK2;
       if (truck3.isSelected())
           truckCost = TRUCK3;
       return truckCost;


import java.awt.GridLayout;
import javax.swing.JCheckBox;
import javax.swing.JFrame;

import java.awt.GridLayout;
import javax.swing.JFrame;
import javax.swing.JRadioButton;

public class WheelPanel extends JFrame

   private final double WHEEL1 = 35.00;
   private final double WHEEL2 = 40.00;
   private final double WHEEL3 = 45.00;

   private JRadioButton wheel1;
   private JRadioButton wheel2;
   private JRadioButton wheel3;

   public WheelPanel()
       setLayout(new GridLayout(3,1));

       wheel1 = new JRadioButton("7.75 in axle");
       wheel2 = new JRadioButton("8 in axle");
       wheel3 = new JRadioButton("8.5 in axle");


   public double getWheelCost()
       double wheelCost = 0;

       if (wheel1.isSelected())
           wheelCost = WHEEL1;
       if (wheel2.isSelected())
           wheelCost = WHEEL2;
       if (wheel3.isSelected())
           wheelCost = WHEEL3;
       return wheelCost;


public class ExtraPanel extends JFrame

   private final double EXTRA1 = 20.00;
   private final double EXTRA2 = 22.00;
   private final double EXTRA3 = 24.00;
   private final double EXTRA4 = 28.00;

   private JCheckBox extra1;
   private JCheckBox extra2;
   private JCheckBox extra3;
   private JCheckBox extra4;

   public ExtraPanel()
       setLayout(new GridLayout(3,1));

       extra1 = new JCheckBox("51mm");
       extra2 = new JCheckBox("55mm");
       extra3 = new JCheckBox("58mm");
       extra4 = new JCheckBox("61mm");


   public double getExtraCost()
       double extraCost = 0;

       if (extra1.isSelected())
           extraCost += EXTRA1;
       if (extra2.isSelected())
           extraCost += EXTRA2;
       if (extra3.isSelected())
           extraCost += EXTRA3;
       if (extra4.isSelected())
           extraCost += EXTRA4;

       return extraCost;


import javax.swing.JLabel;
import javax.swing.JPanel;

public class Banner extends JPanel
    public Banner()
        JLabel greeting = new JLabel("Hey Dude, build your custom board");




import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class BoardCreator extends JFrame

    private double taxRate = .06;

    private DeckPanel deck;
    private TruckPanel truck;
    private WheelPanel wheel;
    private ExtraPanel extra;
    private Banner banner;

    private JPanel buttonPanel;
    private JButton calcButton;
    private JButton exitButton;

    public BoardCreator()
        super ("Skate Shop");


        setLayout(new BorderLayout());

        banner = new Banner();
        deck = new DeckPanel();
        truck = new TruckPanel();
        wheel = new WheelPanel();
        extra = new ExtraPanel();


        add(banner, BorderLayout.NORTH);
        add(deck, BorderLayout.WEST);
        add(truck, BorderLayout.CENTER);
        add(wheel, BorderLayout.EAST);
        add(extra, BorderLayout.SOUTH);


        private void buildBoardCreator()
            buttonPanel = new JPanel();
            calcButton = new JButton("Calculate");
            exitButton = new JButton("Exit");

            calcButton.addActionListener(new CalcButtonListener());
            exitButton.addActionListener(new ExitButtonListener());



        private class CalcButtonListener implements ActionListener
            public void actionPerformed(ActionEvent e)
                double subtotal;
                double tax;
                double total;

                subtotal = deck.getDeckCost()+
                tax = subtotal + taxRate;

                total = subtotal + tax;

                DecimalFormat dollar = new DecimalFormat("0.00");

                JOptionPane.showMessageDialog(null, "Subtotal: $"+
                        dollar.format(subtotal) + "\n" +
                        "Tax: $" + dollar.format(tax) + "\n" +
                        "Total: $" + dollar.format(total));

        private class ExitButtonListener implements ActionListener
            public void actionPerformed(ActionEvent e)

 * To change this template, choose Tools | Templates
 * and open the template in the editor.

 * @author Cory
public class Board 
    public static void main(String[] args)
        new BoardCreator();


Edited 3 Years Ago by Dani: Formatting fixed

Well, take a look at line 40, since that is where the error is occurring.

at BoardCreator.<init>(BoardCreator.java:40)


Im not seeing any error in that line, it is set up the same way as the line above it, which doesn't show an error, and copied in the same manner as in my book..

Well, perhaps you should post that line then, because personally I don't want to spend time counting down 40 lines in all that code that you posted (and it's doubtful that anyone else does either).
And read carefully the description of the error - it's pretty straightforward.

add(banner, BorderLayout.NORTH);
        add(deck, BorderLayout.WEST);
        add(truck, BorderLayout.CENTER);
        add(wheel, BorderLayout.EAST);
        add(extra, BorderLayout.SOUTH);
adding a window to a container!

redefine Your classes as ...

public class ...Panel extends JPanel    // NOT JFrame


This article has been dead for over six months. Start a new discussion instead.