• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problems Calculating the Sum of Elements within a Jlist...  RSS feed

 
Hasan Ali
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently in the process of creating a shopping cart simulation. The main GUI consists of two lists, one is a list of the inventory. (products stored within a .dat file which is automatically loaded upon launch) The other is blank and is to model my shopping basket. The idea is to be able to scan items from my inventory into the checkout basket. As this is happening i want a text field i created to dynamically update with the cost of all the items in the basket.

Below is the method for my scan button, which is supposed to perform the above :



Currently however scanning the item will add it to the list but print strange results in the total. (Adds 5.5 for each item regardless of their actual value**). It will also print a line under the item name as such javax.swing.JList[,0,0,344x326,layout=java.awt.BorderLa... .

Below are the classes for my CartItem and ItemList if they may help. Thank you.

-Cart Item




-ItemList

 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A Jlist isn't intended for storing items and counting them. I would have thought you want a java.util.List instead. Or even a Map which allows you to map the items against how many have been ordered.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!