Good day.. i'm working on a program in GUI and i'm having a problem on how to call the value from itemstatechanged to the actionlistener using the RADIO BUTTON. Code: private class OrderButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { double numItem, kilo; String name; kilo = Double.parseDouble(pkTF.getText()); name = (customerTF.getText()); numItem = (ItemEvent.SELECTED); JOptionPane.showMessageDialog(null, "Customer: " + name + "\n" + "Ordered: " + kilo + " kilo(s)" + "\n" + "The Price is: " + numItem); } } private class RadioListener implements ItemListener { public void itemStateChanged(ItemEvent event) { double num; if (event.getSource() == appleRB){ num = 30; } else if (event.getSource() == orangeRB){ num = 20; } else if (event.getSource() == bananaRB) { num = 20; } else if (event.getSource() == grapeRB){ num = 40; } else if(event.getSource() == mangoRB){ num = 40; } event.getItem(); } } the price(numItem) should be the PRODUCT of the kilos entered and the fruit selected, but the output is (1) i think its from the "ItemEvent.SELECTED" how can i call the value "NUM" selected in itemstatechanged and assign it to the "numItem" in actionlistener? and if you have a good suggestion or alternative that i can do about this program please do suggest thanks Godbless!
Code: ............ public class FruitOrder extends JFrame { [COLOR=DarkRed]private double numItem=0;[/COLOR]//add this line there ............ Code: .......... rbgroup.add(mangoRB); [COLOR=DarkRed]rbgroup.clearSelection();[/COLOR]//nothing selected by default rListener = new RadioListener(); ............ Code: ............... private class OrderButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { double kilo; String name; kilo = Double.parseDouble(pkTF.getText()); name = (customerTF.getText()); JOptionPane.showMessageDialog(null, "Customer: " + name + "\n" + "Ordered: " + kilo + " kilo(s)" + "\n" + "The Price is: " + numItem[COLOR=DarkRed]*kilo[/COLOR]); } } .......... Code: public void itemStateChanged(ItemEvent event) { if (event.getSource() == appleRB){ [COLOR=DarkRed] numItem = 30;[/COLOR]//since we declared this as a global variable } else if (event.getSource() == orangeRB){ [COLOR=DarkRed] numItem = 20;[/COLOR] } else if (event.getSource() == bananaRB) { [COLOR=DarkRed]numItem = 20;[/COLOR] } else if (event.getSource() == grapeRB){ [COLOR=DarkRed]numItem = 40;[/COLOR] } else if(event.getSource() == mangoRB){ [COLOR=DarkRed]numItem = 40;[/COLOR] } event.getItem(); }
Sir Vixen thank you very much! it worked! can i add you as a friend here? this is my first time here, and joined this forum to learn more about programming and stuff. till next time!