Reputation: 23
created getters and setters for the price and count in item class
public static double getItemPrice() {
return itemPrice;
}
public void setItemPrice(double itemPrice) {
this.itemPrice = itemPrice;
}
public static double getItemCount() {
return itemCount;
}
in the store class I created the variable
private static double SubTotal = Item.itemPrice * Item.itemCount;
in the cart panel I have
JLabel subtotal = new JLabel("SubTotal: $" + SubTotal);
basketPanel.add(subtotal, BorderLayout.WEST);
when I execute and add items to the cart, the subtotal comes up like "$0.0" it doesn't change. any suggestions?
Upvotes: 0
Views: 63
Reputation: 2147
The SubTotal value does not update the subtotal text in the JLabel.
In order to propagate it you need to update the JLabel text like:
public void updateSubtotal() {
double newSubTotal = sumAllPrices();
this.subtotal.setText("SubTotal: $" + newSubTotal ); //subtotal is the JLabel
}
Upvotes: 1