smh
smh

Reputation: 23

how do I get a Label to appear in a Panel?

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

Answers (1)

Leet-Falcon
Leet-Falcon

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

Related Questions