# Java programming



## kurosagi01 (Mar 31, 2014)

Hey guys need some help if possible,i am creating a shop through java and i am little stuck on finalising the subtotal and total cost of items.
The subtotal is Excluding the VAT price and total cost is cost of item including VAT.
The way i have designed this is by using JButtons method to add items to the list, which contains the value of item such as 599.99.
The price of items are declared as a double value aswell so double item1 599.99; for example
How would i go about adding multiple variables altogether into the subtotal/total field? The subtotal and totalfield is initialised in JtextField method.
For example 599.99(item1/button1) + 239.99 (item2/button2) = 839.98(subtotal field)

Much advice would be appreciated without providing my code.


----------



## FordGT90Concept (Mar 31, 2014)

If I'm understanding you right, you'll want to add an event to the list that raises when the list is changed.  On change, you'll update the UI.


----------



## kurosagi01 (Mar 31, 2014)

Any form of example you can provide but yeah that sounds about right.


----------



## FordGT90Concept (Mar 31, 2014)

What is the class you're using for the list?


----------



## kurosagi01 (Mar 31, 2014)

Furniture Shop class with GUI using jframe,jpanel, jbutton and jtextfield if that helps?


----------



## FordGT90Concept (Mar 31, 2014)

Oh, so you're not using a UI list?  You're only showing the results in JTextField?  In which case, the code that updates the textfield should be in the JButton ActiveListener.  You'll use a for loop to go through your list doing the math then at the end, you'll use the JTextField's .setText method to display the result.


----------



## kurosagi01 (Mar 31, 2014)

Well i am using JList to list the shopping cart.
I have used that method of setting textfield within the get.source for each button which does display the variable from double value.
However i cannot get like a final estimate value,if i press a different item it would replace whatever was last displayed so it go 599.99+ xx.xx it just go 599.99 to display item 2 value of 299.99.


----------



## FordGT90Concept (Mar 31, 2014)

You'll need to loop through the JList to add it up then put that total in the JTextField.  ListSelectionListener should help a lot.


----------

