I am getting the following error...
init:
deps-jar:
compile-single:
run-single:
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");
add(masterThrasher);
add(dictator);
add(streetKing);
}
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");
add(truck1);
add(truck2);
add(truck3);
}
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");
add(wheel1);
add(wheel2);
add(wheel3);
}
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");
add(extra1);
add(extra2);
add(extra3);
add(extra4);
}
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");
add(greeting);
}
}
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");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
banner = new Banner();
deck = new DeckPanel();
truck = new TruckPanel();
wheel = new WheelPanel();
extra = new ExtraPanel();
buildBoardCreator();
add(banner, BorderLayout.NORTH);
add(deck, BorderLayout.WEST);
add(truck, BorderLayout.CENTER);
add(wheel, BorderLayout.EAST);
add(extra, BorderLayout.SOUTH);
pack();
setVisible(true);
}
private void buildBoardCreator()
{
buttonPanel = new JPanel();
calcButton = new JButton("Calculate");
exitButton = new JButton("Exit");
calcButton.addActionListener(new CalcButtonListener());
exitButton.addActionListener(new ExitButtonListener());
buttonPanel.add(calcButton);
buttonPanel.add(exitButton);
}
private class CalcButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
double subtotal;
double tax;
double total;
subtotal = deck.getDeckCost()+
truck.getTruckCost()+
wheel.getWheelCost()+
extra.getExtraCost();
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)
{
System.exit(0);
}
}
}
/*
* 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();
}
}