473,670 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What does "java.awt.Butto n cannot be cast to javax.swing.JCo mboBox" mean?

13 New Member
i have this unfinished java program and i can't figure out what is the problem..

please help...

/**
* @(#)Answer3.jav a
*
*
* @author
* @version 1.00 2008/1/17
*/
import javax.swing.*;
import java.awt.*;
import java.applet.*;
import java.awt.event. *;
import javax.swing.bor der.*;

public class Answer3 extends Applet implements ActionListener {

//declaration of instance variables
CheckboxGroup radioGroup2;
TextField tf1, tf2, tf3;
JComboBox flavorsCombo;
Button addPizza;
Checkbox Personal, Regular, Family;
Checkbox Bacon, Beef, Ham, Pepperoni, Onions,Pineappl e, Cheese, Mushroom;
int pricePersonal = 150,
priceRegular = 250,
priceFamily = 400,
priceTopping = 20,
total = 0;

public void init() {

JPanel panel = new JPanel();
//displays the name of the program
JLabel programName = new JLabel (" Pizza Station Ordering Software ");
programName.set Font (new Font ("Arial", Font.BOLD, 18));
panel.add(progr amName);
panel.setBorder (new EtchedBorder()) ;
panel.setLayout (new GridLayout(1,5, 20,50));
add(panel);

JPanel panel1 = new JPanel();
//initializes the JCombobox
flavorsCombo = new JComboBox();
flavorsCombo.ad dItem("Hawaiian ");
flavorsCombo.ad dItem("Mozzarel la");
flavorsCombo.ad dItem("Pepperon i");
panel1.add(flav orsCombo);
flavorsCombo.ad dActionListener (this);
panel1.setBorde r(new TitledBorder(ne w EtchedBorder(), "Pizza Flavors"));
add(panel1);

//declares a new category of CheckboxGroup
CheckboxGroup radioGroup1 = new CheckboxGroup() ;

//initializes the radio buttons for radioGroup1
Personal = new Checkbox("Perso nal",radioGroup 1,true);
Regular = new Checkbox("Regul ar",radioGroup1 ,false);
Family = new Checkbox("Famil y",radioGroup1, false);

//initializes the radio buttons for radioGroup2
Bacon = new Checkbox("Bacon ",radioGroup2,f alse);
Beef = new Checkbox("Beef ",radioGroup2,f alse);
Ham = new Checkbox("Ham ",radioGroup2,f alse);
Pepperoni = new Checkbox("Peppe roni ",radioGroup2,f alse);
Onions = new Checkbox("Onion s ",radioGroup2,f alse);
Pineapple = new Checkbox("Pinea pple ",radioGroup2,f alse);
Cheese = new Checkbox("Chees e ",radioGroup2,f alse);
Mushroom = new Checkbox("Mushr oom ",radioGroup2,f alse);

//TitledBorder which displays the radioButtons of CheckboxGroup1
JPanel panel2 = new JPanel();
panel2.add(Pers onal);
panel2.add(Regu lar);
panel2.add(Fami ly);
panel2.setBorde r(new TitledBorder(ne w EtchedBorder(), "Pizza Flavors"));
add(panel2);

//TitledBorder which displays the radioButtons of CheckboxGroup2
JPanel panel3 = new JPanel();
panel3.add(Baco n);
panel3.add(Beef );
panel3.add(Ham) ;
panel3.add(Pepp eroni);
panel3.add(Onio ns);
panel3.add(Pine apple);
panel3.add(Chee se);
panel3.add(Mush room);
panel3.setBorde r(new TitledBorder(ne w EtchedBorder(), "ExtraToppings" ));
panel3.setLayou t(new GridLayout(3,3, 10,2));
add(panel3);

JPanel panel4 = new JPanel();

JPanel panel5 = new JPanel();
JLabel quantity = new JLabel ("Quantity ");
quantity.setFon t (new Font ("Arial", Font.BOLD, 12));
panel4.add(quan tity);
//initializes the TextField
tf1 = new TextField(5);
tf1.setEditable (true);
panel5.add(tf1) ;
panel5.setBorde r(new EmptyBorder(2,1 0,2,2));
panel4.add(pane l5);

JPanel panel6 = new JPanel();

//initializes the addPizza button
addPizza = new Button("Add Pizza to Order List");
addPizza.addAct ionListener(thi s);
panel6.add(addP izza);
panel6.setBorde r(new EmptyBorder(2,2 ,2,24));
panel4.add(pane l6);
panel4.setBorde r(new EtchedBorder()) ;
add(panel4);

//TitledBorder which displays the JTextArea
JPanel panel7 = new JPanel();

//initializes the JTextArea
JTextArea pizzaOrders = new JTextArea(8,28) ;
pizzaOrders.set Editable(false) ;
panel7.add(pizz aOrders);
panel7.setBorde r(new TitledBorder(ne w EtchedBorder(), "Pizza Orders"));
add(panel7);

JPanel panel8 = new JPanel();

//initializes the name entry
JLabel name = new JLabel("Name ");
name.setFont(ne w Font("Arial",Fo nt.BOLD,12));
panel8.add(name );
tf2 = new TextField(19);
panel8.add(tf2) ;
panel8.setBorde r(new EtchedBorder()) ;
add(panel8);

JPanel panel9 = new JPanel();


JLabel total = new JLabel("Total ");
total.setFont(n ew Font("Arial",Fo nt.BOLD,12));
panel9.add(tota l);
tf3 = new TextField(5);
tf3.setEditable (false);
panel9.add(tf3) ;
panel9.setBorde r(new EtchedBorder()) ;
add(panel9);

}


public void actionPerformed (ActionEvent e){
JComboBox cb = (JComboBox)e.ge tSource();
String flavorPizza = (String)cb.getS electedItem();



if (e.getSource() == addPizza)
JOptionPane.sho wMessageDialog( null,"NONSENSE" );



}

}
Jan 19 '08 #1
2 8720
JosAH
11,448 Recognized Expert MVP
I'm sure your compiler mentioned a line number when it bumped in to that problem.
If/when you want your problem solved on this forum please supply us with all the
information you received when you hit the problem. A quick hint: you are messing
with AWT objects as well as Swing objects and that is generally not done. A
Button in the AWT library most certainly is not a Swing JComboBox component.
You try to treat one as the other somewhere in your code.

kind regards,

Jos
Jan 19 '08 #2
HaifaCarina
13 New Member
I'm sure your compiler mentioned a line number when it bumped in to that problem.
If/when you want your problem solved on this forum please supply us with all the
information you received when you hit the problem. A quick hint: you are messing
with AWT objects as well as Swing objects and that is generally not done. A
Button in the AWT library most certainly is not a Swing JComboBox component.
You try to treat one as the other somewhere in your code.

kind regards,

Jos
Thanks Jos!I did some confusing move but i did finish this program...! Congratulations self!
Jan 27 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2201
by: Miles Davenport | last post by:
I would like some advice on what Java server-side alternatives their are to an applet which is a shopping cart application which allows the user to drag-and-drop individual items into "an order" panel within the applet environment on the browser client. I am eager to port this application, as the rest of the site uses JSP, servlets, XML, struts..... I do not have much experience of Swing, but would like to know if there is a way of...
1
2659
hirak1984
by: hirak1984 | last post by:
hi,I am trying to use back button that will take me to previous page.But even if it happens,the current page is still remaining full screen,if you minimize this page,only then you could get to the previous page.please help me solve this problem.I am using swing for my code
11
7693
by: hamiltongreg | last post by:
I am new to Java and am having problems getting my program to compile correctly. My assignment is as follows; Choose a product that lends itself to an inventory (for example, products at your workplace, office supplies, music CDs, DVD movies, or software). • Create a product class that holds the item number, the name of the product, the number of units in stock, and the price of each unit. • Create a Java application that displays the...
1
1784
by: GHKASHYAP | last post by:
Hi this is the exception i am getting when i am trying to run this application: Exception in thread "main" java.lang.NullPointerException thanks in advance.. package com.inventive.StockMarketTrading; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent;
3
2572
by: gator6688 | last post by:
import java.text.DecimalFormat; import javax.swing.JOptionPane; public class PayrollSystemTest { public static void main( String args ) { String workerType; String first; String last;
49
2883
by: aarklon | last post by:
Hi all, See:- http://www.cs.princeton.edu/introcs/faq/c2java.html for C vs Java in number crunching http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
4
14719
by: jmitch89 | last post by:
I don't why I get this error: Exception in thread "main" java.lang.NoClassDefFoundError The statement below works just fine: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar";CurrentStrobe.jar com.visionpro.currentstrobe.CurrentStrobeApp However, the statement below produces the error: java -cp "appframework-1.0.3.jar;swing-worker-1.1.jar" -jar CurrentStrobe.jar Exception in thread "main"...
2
3950
by: lilyumestar | last post by:
This project is due by Tuesday and I haven't even gotten half of it done. Can anyone please help me with this Exception error? I've been trying to figure it out for several hours Error Message "Main" Java.lang NullPointerException at Project1.sortingByZipCode<Project1.java:80> at Project1.main<Project1.java:31> Here is the Source Code
1
6750
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread "main" java.lang.NullPointerException at java.awt.Container.addImpl(Container.java:1041) at java.awt.Container.add(Container.java:365) at orderingsystem.OrderingSystem.<init>(OrderingSystem.java:261) at...
0
8384
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8901
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8813
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8591
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7412
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6212
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4388
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2037
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1791
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.