title: How to sum total from 3 combobox depending on what a user select in the combobox
body: <p>I want the user select food from 3 comboBox based on they select the output. For example if they choose rice then it will add 200 and if they choose one more fish(100) then it will calculated the price become 300. The error I have is that my combobox is not calculated though user have selected the output and always display 0</p>
  <p>Here is the code</p>
  <pre><code>public class MainMenu extends JFrame implements ItemListener{
      int total1;
      int total2;
      int total3;
      int total4 = 0;
      JLabel totalconsumed;
      String breakfast_food1[] = {&quot;Add food&quot;, &quot;Rice&quot;, &quot;Fish&quot;, &quot;Egg&quot;, &quot;Chicken&quot;};
      int breakfastcalorie1[] = {0, 200, 100, 50, 25};
      String breakfast_food2[] = {&quot;Add food&quot;, &quot;Rice&quot;, &quot;Fish&quot;, &quot;Egg&quot;, &quot;Chicken&quot;};
      int breakfastcalorie2[] = {0, 200, 100, 50, 25};
      String breakfast_food3[] = {&quot;Add food&quot;, &quot;Rice&quot;, &quot;Fish&quot;, &quot;Egg&quot;, &quot;Chicken&quot;};
      int breakfastcalorie3[] = {0, 200, 100, 50, 25};
      
      public MainMenu() {
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize( 450, 520);
          setVisible(true);
          JPanel contentPane = new JPanel();
          contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
          setContentPane(contentPane);
          contentPane.setLayout(null);
          
          
          
          JLabel date = new JLabel(&quot;Monday, March 29th 2021&quot;);
          date.setHorizontalAlignment(SwingConstants.CENTER);
          date.setFont(new Font(&quot;Times New Roman&quot;, Font.BOLD, 18));
          date.setBounds(77, 11, 259, 14);
          contentPane.add(date);
          
          JPanel panel = new JPanel();
          panel.setBorder(new LineBorder(SystemColor.activeCaption, 3));
          panel.setBounds(10, 47, 414, 74);
          panel.setLayout(new GridLayout(3, 2, 5, 5));
          contentPane.add(panel);
          
          JLabel calorie_goal = new JLabel(&quot;My Calorie Goal&quot;);
          calorie_goal.setFont(new Font(&quot;Tempus Sans ITC&quot;, Font.BOLD, 14));
          panel.add(calorie_goal);
          
          JTextField goal = new JTextField(&quot;1500 calories&quot;);
          panel.add(goal);
          
          JLabel consumed = new JLabel(&quot;Consumed&quot;);
          consumed.setFont(new Font(&quot;Tempus Sans ITC&quot;, Font.BOLD, 14));
          panel.add(consumed);
          
          JTextField total_consumed = new JTextField();
          panel.add(total_consumed);
          
          JLabel remaining = new JLabel(&quot;Remaining&quot;);
          remaining.setFont(new Font(&quot;Tempus Sans ITC&quot;, Font.BOLD, 14));
          panel.add(remaining);
          
          JTextField total_remaining = new JTextField();
          panel.add(total_remaining);
          
          JPanel panel1 = new JPanel();
          panel1.setLayout(null);
          panel1.setBorder(new LineBorder(SystemColor.activeCaption, 3, true));
          panel1.setBounds(10, 240, 415, 80);
          contentPane.add(panel1);
          
          JPanel panel1a = new JPanel();
          panel1a.setBounds(3, 3, 408, 26);
          panel1a.setLayout(new GridLayout(0, 4, 5, 0));
          panel1.add(panel1a);
          
          JLabel breakfast = new JLabel(&quot;Breakfast&quot;);
          breakfast.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 18));
          panel1a.add(breakfast);
          
          
          JComboBox breakfast1 = new JComboBox(breakfast_food1);
          panel1a.add(breakfast1);
          
          
          JComboBox breakfast2 = new JComboBox(breakfast_food2);
          panel1a.add(breakfast2);
          
          
          JComboBox breakfast3 = new JComboBox(breakfast_food3);
          panel1a.add(breakfast3);
          
          JPanel panel1b = new JPanel();
          panel1b.setBounds(3, 33, 410, 45);
          panel1b.setLayout(new GridLayout(2, 2, 5, 5));
          panel1.add(panel1b);
          
          JLabel breakfast_calorie = new JLabel(&quot;Recommended Calories&quot;);
           breakfast_calorie.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 16));
           panel1b.add(breakfast_calorie);
          
          JTextField breakfast_text = new JTextField();
          breakfast_text.setText(&quot;730 calories&quot;);
          breakfast_text.setFont(new Font(&quot;Tahoma&quot;, Font.BOLD, 12));
          panel1b.add(breakfast_text);
          
          JLabel breakfast_consumed = new JLabel(&quot;Total Consumed&quot;);
           breakfast_consumed.setFont(new Font(&quot;Serif&quot;, Font.BOLD, 14));
          panel1b.add( breakfast_consumed);
          
          totalconsumed = new JLabel(&quot;Total consumed is &quot; + total4);
          panel1b.add(totalconsumed);
          
          
          breakfast1.addItemListener(this);
          breakfast2.addItemListener(this);
          breakfast3.addItemListener(this);
      }
      
  
      
      public void itemStateChanged(ItemEvent e, JComboBox breakfast1, JComboBox breakfast2, JComboBox breakfast3) {
          Object source = e.getSource();
          if(e.getStateChange()==ItemEvent.SELECTED) {
              if(source.equals(breakfast1) || source.equals(breakfast2) || source.equals(breakfast3)) {
                  total1 = breakfastcalorie1[breakfast1.getSelectedIndex()];
                  total2 = breakfastcalorie2[breakfast2.getSelectedIndex()];
                  total3 = breakfastcalorie3[breakfast3.getSelectedIndex()];
                  total4 = total1 + total2 + total3;
                  totalconsumed.setText(&quot;Total consumed is  &quot; + total4);
              };
          }
      }
  
  public static void main(String[] args) {
      new MainMenu();
  
  }
  
  @Override
  public void itemStateChanged(ItemEvent e) {
      // TODO Auto-generated method stub
      
  }
  
  }
  </code></pre>