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 8914231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:40:03+00:00 2026-06-15T04:40:03+00:00

i’m having a bit of a problem. Here’s the situation. I have an amount

  • 0

i’m having a bit of a problem. Here’s the situation. I have an amount field in my main class that gets incremented when certain buttons are clicked on. There is a method provided through which you can delete any order (I’m basically programming for a restaurant terminal) and the amount gets decremented. The delete method is placed in another class.

public void posdel(int pos, JTextField amountFieldGot, int amountGot)
{
    if(slist==null)
    {
        JOptionPane.showMessageDialog(null, "No order has been placed yet.",null,JOptionPane.WARNING_MESSAGE);
    }
    else
    {
        if(pos==1)
        {
            reductionAmount = (slist.quantity*slist.price);
            amountGot = amountGot - reductionAmount;
            slist=slist.next;
        }
        else
        {
            int i=1;
            Node temp=slist;
            Node prev=null;
            while(temp.next!=null && i<pos)
            {
                prev=temp;
                temp=temp.next;
                i++;
            }
            if(pos==i)
            {
                prev.next=temp.next;
            }
            else
            {
                JOptionPane.showMessageDialog(null, "Invalid order", null, JOptionPane.ERROR_MESSAGE);
            }
        }
    }
    amountFieldGot.setText(Integer.toString(amountGot));
}

So basically, I have an amountField in my GUI that i pass as a parameter to the posdel method. I also pass the amount value as a parameter. The new amount that i get is amountGot after the deletion of the first order. ( I haven’t written the code for other positions.)
Suppose the amount value i pass into the method is 30 (14+16) 14 = order 1, 16 = order2.
And my first order has a value of 14.
So amountGot = 30 – 14 which is 16.
And the amountField in the GUI gets updated to 16.
Now my order 2 becomes my order 1. And if i try to delete this,
my amountField gets update to 14. (30-16 = 14).
So i’m guessing the amount value stays the same itself as 30 and does not get updated to the new amountGot value. Can someone please help me solve this problem ?

below is the code for my delete button.

deleteButton.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                dishDelPos = JOptionPane.showInputDialog("Enter the position of the order to be deleted");
                try
                {
                    dishDeletePosition = Integer.parseInt(dishDelPos);
                    order1.posdel(dishDeletePosition, amountField, amount);
                    repaint();
                }
                catch(NumberFormatException ex1)
                {
                    JOptionPane.showMessageDialog(null,"This is not a valid position");
                }
            }
        });
  • 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-15T04:40:04+00:00Added an answer on June 15, 2026 at 4:40 am

    A few things.

    You can make the delete method in the class static. The you would reference it

     value = MyClass.deleteMethod();
    

    You can create a new class to perform the method

    MyClass myClass = new MyClass();
    value = myClass.deleteMethod();
    

    You can do it using a pointer of sorts, by passing in a reference to an already existing instance of the class holding the delete method, to where you want to call it.

     myFunction(MyClass myClass)
     {
        value = myClass.deleteMethod();
     }
    

    basically set up your function to return a value

    public static int deleteMethod()
    {
    }
    

    this function returns an int.

    or if you need to return more than that then set the class up with global variables of information

    class MyClass
    {
       public int value1;
       public int value2;
       public String value3;
    
       public void deleteMethod()
       {
           //does something with global variables
       }
    }
    

    now fetch the info after calling delete like so

    Myclass myClass = new MyClass();
    myClass.deleteMethod();
    value1 = myClass.value1
    value2 = myClass.Value2
    value3 = myClass.Value3
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have been unable to fix a problem with Java Unicode and encoding. The
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.