Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8736545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:19:37+00:00 2026-06-13T10:19:37+00:00

I have my Store class wherein i could add items to cart then it

  • 0

I have my Store class wherein i could add items to cart then it will increment the cart item number and the total amount.

I also have a view cart button like thing, if it is clicked it will show another frame where the items from the cart shows. When i click remove button from this cart frame i plan to decrement the count and total amount from the previous frame, but the setText method i used in the jLabel where the total price is located don’t work.

I call this method from the cart frame then pass the price to be removed whenever i click the remove button

public void updateTotalAmount(double deduct){
    System.out.println("updateTotalAmount - "+deduct);
    tAPriceL.setText(String.valueOf(deduct)); //Total amount price label
    cICountL.setText(String.valueOf(--cICount)); //cart item count label
}

the system.out line is the only statement that works, the rest don’t.

when i try to interchange the code like this.

public void updateTotalAmount(double deduct){
    tAPriceL.setText(String.valueOf(deduct)); //Total amount price label
    cICountL.setText(String.valueOf(--cICount)); //cart item count label
    System.out.println("updateTotalAmount - "+deduct);
}

the system.out now didn’t work so i guess there is a problem on the setText part.

I can’t figure out where is the problem.
Could anyone help me with this?

here is the summary of this..
for the main store class.. example i have 5000 worth of items

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class NewClass extends JFrame implements ActionListener {

    JLabel tAPrice = new JLabel("5000");
    JButton viewcart = new JButton("view cart");

    public NewClass() {
        this.setLayout(new FlowLayout());
        add(tAPrice);
        add(viewcart);
        viewcart.addActionListener(this);
    }

    public static void main(String[] args) {
        NewClass n = new NewClass();
        n.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        n.setSize(1150, 730);
        n.setVisible(true);
    }

    public void update(double deduct) {
        System.out.println("updated");
        tAPrice.setText(String.valueOf(Double.parseDouble(tAPrice.getText())
            - deduct));
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == viewcart) {
            Cart2 c = new Cart2();
            c.setVisible(true);
            c.setSize(250, 230);
        }
    }
}

and for the cart class… for example i wanna remove 1000 from the total amount

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

public class Cart2 extends JFrame implements ActionListener {

    JButton remove = new JButton("remove");

    public Cart2() {
        add(remove);
        remove.addActionListener(this);
    }

    public static void main(String[] args) {
        Cart2 r = new Cart2();
        r.setVisible(true);
        r.setSize(250, 230);
        r.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == remove) {
            NewClass nc = new NewClass();
            nc.update(1000);
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T10:19:38+00:00Added an answer on June 13, 2026 at 10:19 am

    In Cart2.actionPerformed() you’re allocating new NewClass() instead of using the calling instance of NewClass. Try passing instance of NewClass into Cart2 constructor.

    For example:

    public class Cart2 extends JFrame implements ActionListener {
        JButton remove = new JButton("remove");
        NewClass newClass;
    
        public Cart2(NewClass newClass) {
            this.newClass = newClass;
            add(remove);
    
            remove.addActionListener(this);
        }
    
        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == remove) {
                // NewClass nc = new NewClass();
                newClass.update(1000);
            }
        }
    
    }
    

    Then in NewClass:

    @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == viewcart) {
            Cart2 c = new Cart2(this);
            c.setVisible(true);
            c.setSize(250, 230);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program in which I need to store a Class object into
In this scenario, I have 2 or more models: class Store(models.Model): name = models.CharField(max_length
I have a class of students which I store into set in my cpp
I have a class in c# in that store some user messages, and return
I have a class in silverlight that I would like to store to disk.
I have small class called 'Call' and I need to store these calls into
I have settings that I store in my database. There is an entity class
I have the following objective C class. It is to store information on a
If I have a class with some value member that I want to store
I have a field URL countryURL; in a Country class. I want to store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.