Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Help Me On This Please (http://www.go4expert.com/forums/help-t23398/)

DiceV2 23Sep2010 21:43

Help Me On This Please
 
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!

virxen 24Sep2010 02:19

Re: Help Me On This Please
 
send all your project here in a zip file and use code tags for your code.

DiceV2 24Sep2010 06:46

Re: Help Me On This Please
 
1 Attachment(s)
hope you can help me as soon as possible thanks.. Godbless
the project is attached..

virxen 25Sep2010 04:11

Re: Help Me On This Please
 
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();
        }


DiceV2 25Sep2010 07:44

Re: Help Me On This Please
 
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!


All times are GMT +5.5. The time now is 11:53.