java - JFrame and ItemListener Issues -


i cannot figure out debug class.

as comments say, needs have user enter pizza toppings , gives price back. has code have no clue start on debug.

anything help, or if have working code help. want learn need help. thank in advance help/nudge in right direction.

// debugfourteen3 // user selects pizza topping , sees price import javax.swing.*; import java.awt.*; import java.awt.event.*;  //use correct spelling of class name public class debugfourteen3 extends jframe implements itemlistener {    flowlayout flow = new flowlayout();    jcombobox pizzabox = new jcombobox();    jlabel toppinglist = new jlabel("topping list");    jlabel alabel = new jlabel("paulos's american pie");    jtextfield totprice = new jtextfield(10);    int[] pizzaprice = {7,10,10,8,8,8,8};    int totalprice = 0;    string output;    int pizzanum;    public debugfourteen3()    {       super("pizza list");       setdefaultcloseoperation(jframe.exit_on_close);       setlayout(flow);       pizzabox.additemlistener(this);       add(toppinglist);       pizzabox.additem("cheese");       pizzabox.additem("sausage");       pizzabox.additem("pepperoni");       pizzabox.additem("onion");       pizzabox.additem("green pepper");       pizzabox.additem("green olive");       pizzabox.additem("black olive");       add(pizzabox);       add(alabel);       add(totalprice);    }    public static void main(string[] arguments)    {       jframe frame = new debugfourteen3();       frame.setsize(200, 150);       frame.setvisible(true);    }     public void itemstatechanged(itemevent[] list)    {       object source = list.getsource();       if(source == pizzabox)       {          int pizzanum = pizzabox.getselectedindex();          totalprice = pizzaprice[x];          output = "pizza price $" + totalprice;          totprice.settext(output);       }    } } 

  • add(totalprice); int, can not added container. use jlabel, jtextfield or jformattedtextfield instead
  • public void itemstatechanged(itemevent[] list) { not valid signature contractual requirements of itemlistener. see javadocs requirement method signature honor contractual requirements, take care of @ least 2 other errors
  • totalprice = pizzaprice[x];, x undefined (or more point, defined private variable in component , can reference it, think want pizzanum

personally, think find easier use actionlistener instead of itemlistener care change in selected item, not change old selected item new selected item


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

ios - Possible to get UIButton sizeThatFits to work? -