Help Me On This Please

DiceV2's Avatar, Join Date: Sep 2010
Newbie Member
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!

Last edited by shabbir; 24Sep2010 at 09:14.. Reason: Code blocks
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
send all your project here in a zip file and use code tags for your code.
0
DiceV2's Avatar, Join Date: Sep 2010
Newbie Member
hope you can help me as soon as possible thanks.. Godbless
the project is attached..
Attached Files
File Type: zip oopl04c_c234.zip (92.9 KB, 5 views)
0
virxen's Avatar, Join Date: Nov 2009
Pro contributor
Code:
............
public class FruitOrder extends JFrame 
{
    private double numItem=0;//add this line there
............
Code:
..........
        rbgroup.add(mangoRB);
        rbgroup.clearSelection();//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*kilo);
        }
    }
..........



Code:
public void itemStateChanged(ItemEvent event)
        {
            if (event.getSource() == appleRB){
                numItem = 30;//since we declared this as a global variable
            }
            else if (event.getSource() == orangeRB){
                numItem = 20;
            }
            else if (event.getSource() == bananaRB) {
                numItem = 20;
            }
            else if (event.getSource() == grapeRB){
                numItem = 40;
            }
            else if(event.getSource() == mangoRB){
                numItem = 40;
            }
            event.getItem();
        }
0
DiceV2's Avatar, Join Date: Sep 2010
Newbie Member
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!