| | |
Help with an error...
![]() |
•
•
Join Date: Sep 2008
Posts: 37
Reputation:
Solved Threads: 0
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...
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;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 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; } }
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();
}
} Well, take a look at line 40, since that is where the error is occurring. .
Java Syntax (Toggle Plain Text)
at BoardCreator.<init>(BoardCreator.java:40)
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.
And read carefully the description of the error - it's pretty straightforward.
Last edited by Ezzaral; Nov 18th, 2008 at 4:30 pm.
•
•
Join Date: Nov 2008
Posts: 327
Reputation:
Solved Threads: 50
Java Syntax (Toggle Plain Text)
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!
Java Syntax (Toggle Plain Text)
public class ...Panel extends JPanel // NOT JFrame
![]() |
Similar Threads
- Code 19 Registry Error (Windows NT / 2000 / XP)
- Error Loading operating System (Windows NT / 2000 / XP)
- svchost.exe error (Windows NT / 2000 / XP)
- New Hardware Causing Error (Windows NT / 2000 / XP)
- office 2000 install error (Windows NT / 2000 / XP)
- VMWare Unrecoverable Error (*nix Software)
- Error in Wrox Book (Perl)
Other Threads in the Java Forum
- Previous Thread: tab separated file
- Next Thread: Listing questions
| Thread Tools | Search this Thread |
-xlint 911 actionlistener addressbook android applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer csv database desktop developmenthelp eclipse error fractal ftp functiontesting game gameprogramming givemetehcodez graphics gui html image j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac method mobile myregfun netbeans notdisplaying number objects online oriented printf problem program projects qt recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update variablebinding windows xor






