title: How to return a value from one class to another ? Java
body: <p>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.</p>
  
  <pre><code>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 &amp;&amp; i&lt;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));
  }
  </code></pre>
  
  <p>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 ?</p>
  
  <p>below is the code for my delete button.</p>
  
  <pre><code>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");
                  }
              }
          });
  </code></pre>