472,794 Members | 1,851 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,794 software developers and data experts.

What does "java.awt.Button cannot be cast to javax.swing.JComboBox" mean?

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

please help...

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

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,Pineapple, 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.setFont (new Font ("Arial", Font.BOLD, 18));
panel.add(programName);
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.addItem("Hawaiian");
flavorsCombo.addItem("Mozzarella");
flavorsCombo.addItem("Pepperoni");
panel1.add(flavorsCombo);
flavorsCombo.addActionListener(this);
panel1.setBorder(new TitledBorder(new EtchedBorder(), "Pizza Flavors"));
add(panel1);

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

//initializes the radio buttons for radioGroup1
Personal = new Checkbox("Personal",radioGroup1,true);
Regular = new Checkbox("Regular",radioGroup1,false);
Family = new Checkbox("Family",radioGroup1,false);

//initializes the radio buttons for radioGroup2
Bacon = new Checkbox("Bacon",radioGroup2,false);
Beef = new Checkbox("Beef ",radioGroup2,false);
Ham = new Checkbox("Ham ",radioGroup2,false);
Pepperoni = new Checkbox("Pepperoni ",radioGroup2,false);
Onions = new Checkbox("Onions ",radioGroup2,false);
Pineapple = new Checkbox("Pineapple ",radioGroup2,false);
Cheese = new Checkbox("Cheese ",radioGroup2,false);
Mushroom = new Checkbox("Mushroom ",radioGroup2,false);

//TitledBorder which displays the radioButtons of CheckboxGroup1
JPanel panel2 = new JPanel();
panel2.add(Personal);
panel2.add(Regular);
panel2.add(Family);
panel2.setBorder(new TitledBorder(new EtchedBorder(), "Pizza Flavors"));
add(panel2);

//TitledBorder which displays the radioButtons of CheckboxGroup2
JPanel panel3 = new JPanel();
panel3.add(Bacon);
panel3.add(Beef);
panel3.add(Ham);
panel3.add(Pepperoni);
panel3.add(Onions);
panel3.add(Pineapple);
panel3.add(Cheese);
panel3.add(Mushroom);
panel3.setBorder(new TitledBorder(new EtchedBorder(), "ExtraToppings"));
panel3.setLayout(new GridLayout(3,3,10,2));
add(panel3);

JPanel panel4 = new JPanel();

JPanel panel5 = new JPanel();
JLabel quantity = new JLabel ("Quantity ");
quantity.setFont (new Font ("Arial", Font.BOLD, 12));
panel4.add(quantity);
//initializes the TextField
tf1 = new TextField(5);
tf1.setEditable(true);
panel5.add(tf1);
panel5.setBorder(new EmptyBorder(2,10,2,2));
panel4.add(panel5);

JPanel panel6 = new JPanel();

//initializes the addPizza button
addPizza = new Button("Add Pizza to Order List");
addPizza.addActionListener(this);
panel6.add(addPizza);
panel6.setBorder(new EmptyBorder(2,2,2,24));
panel4.add(panel6);
panel4.setBorder(new EtchedBorder());
add(panel4);

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

//initializes the JTextArea
JTextArea pizzaOrders = new JTextArea(8,28);
pizzaOrders.setEditable(false);
panel7.add(pizzaOrders);
panel7.setBorder(new TitledBorder(new EtchedBorder(), "Pizza Orders"));
add(panel7);

JPanel panel8 = new JPanel();

//initializes the name entry
JLabel name = new JLabel("Name ");
name.setFont(new Font("Arial",Font.BOLD,12));
panel8.add(name);
tf2 = new TextField(19);
panel8.add(tf2);
panel8.setBorder(new EtchedBorder());
add(panel8);

JPanel panel9 = new JPanel();


JLabel total = new JLabel("Total ");
total.setFont(new Font("Arial",Font.BOLD,12));
panel9.add(total);
tf3 = new TextField(5);
tf3.setEditable(false);
panel9.add(tf3);
panel9.setBorder(new EtchedBorder());
add(panel9);

}


public void actionPerformed(ActionEvent e){
JComboBox cb = (JComboBox)e.getSource();
String flavorPizza = (String)cb.getSelectedItem();



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



}

}
Jan 19 '08 #1
2 8608
JosAH
11,448 Expert 8TB
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
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
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"...
1
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...
11
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...
1
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...
3
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;...
49
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
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...
2
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 ...
1
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...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.