1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Java programming

Discussion in 'Programming & Webmastering' started by kurosagi01, Mar 31, 2014.

  1. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,130 (2.02/day)
    Thanks Received:
    415
    Location:
    Northampton,UK
    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.
     
  2. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,723 (6.24/day)
    Thanks Received:
    3,625
    Location:
    IA, USA
    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.
     
    Crunching for Team TPU
  3. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,130 (2.02/day)
    Thanks Received:
    415
    Location:
    Northampton,UK
    Any form of example you can provide but yeah that sounds about right.
     
  4. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,723 (6.24/day)
    Thanks Received:
    3,625
    Location:
    IA, USA
    What is the class you're using for the list?
     
    Crunching for Team TPU
  5. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,130 (2.02/day)
    Thanks Received:
    415
    Location:
    Northampton,UK
    Furniture Shop class with GUI using jframe,jpanel, jbutton and jtextfield if that helps?
     
  6. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,723 (6.24/day)
    Thanks Received:
    3,625
    Location:
    IA, USA
    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.
     
    Crunching for Team TPU
  7. kurosagi01

    kurosagi01

    Joined:
    Mar 21, 2009
    Messages:
    4,130 (2.02/day)
    Thanks Received:
    415
    Location:
    Northampton,UK
    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.
     
  8. FordGT90Concept

    FordGT90Concept "I go fast!1!11!1!"

    Joined:
    Oct 13, 2008
    Messages:
    13,723 (6.24/day)
    Thanks Received:
    3,625
    Location:
    IA, USA
    You'll need to loop through the JList to add it up then put that total in the JTextField. ListSelectionListener should help a lot.
     
    Crunching for Team TPU

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page