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 addedcontainer. usejlabel,jtextfieldorjformattedtextfieldinsteadpublic void itemstatechanged(itemevent[] list) {not valid signature contractual requirements ofitemlistener. see javadocs requirement method signature honor contractual requirements, take care of @ least 2 other errorstotalprice = pizzaprice[x];,xundefined (or more point, definedprivatevariable incomponent, can reference it, think wantpizzanum
personally, think find easier use actionlistener instead of itemlistener care change in selected item, not change old selected item new selected item
Comments
Post a Comment