title: How can I calculate the sum of all elements within my JList ?
body: <p>I'm creating a shopping cart simulation with a list of products that i want to add together and display the total of as they are being added to the cart basket (implemented as a jlist).</p>
  
  <p>In my main  class I have a button with an action listener to take items from my stocklist and add them to the basket.</p>
  
  <pre><code>scanBtn.addActionListener(new ActionListener() {
                      @Override
                      public void actionPerformed(ActionEvent evt) {
                          checkoutBasket.addElement(productList.getSelectedValuesList());
                      }
                  });
  </code></pre>
  
  <p>In addition I have a JTextField set up below the basket which I want to dynamically update with the total cost as I add items to the cart. My question is how could I go about doing this ? Thank you.</p>
  
  <pre><code>                cartTotalField = new JTextField();
                  getContentPane().add(cartTotalField);
                  cartTotalField.setBounds(581, 441, 233, 28);
  </code></pre>
  
  <p>Cart Item Class :  </p>
  
  <pre><code>import java.io.*;
  
  public class CartItem implements Serializable {
  
      private String barcodeNo;
      private String itemName;
      private String price;
  
      public CheckoutItem() {
  
      }
  
      public CheckoutItem (String barno, String in, String cost) {
              barcodeNo = barno;
              itemName = in;
              price = cost;
      }
  
      public String getBarcodeNo(){
          return barcodeNo;
      }
  
      public String getItemName(){
          return itemName;
      }
  
      public void setitemName(String itemName){
              this.itemName = itemName;
          }
  
      public String getPrice(){
          return price;
      }
  
  
      public String toString(){
          return barcodeNo + ": " + itemName + ", " + price;
      }
  
      public Object getID() {
          // TODO Auto-generated method stub
          return null;
      }
  }
  </code></pre>