title: Passing input from one frame to another(JAVA)
body: <p>Here's the thing...</p>
  
  <p>I have 2 GUI programs.<br>
  A Menu Program,which is basically a frame with buttons of food items,the buttons when clicked
  opens this other program,an Input Quantity Program,which is a frame with a text field,buttons for numbers,buttons for Cancel and Confirm. The quantity that is confirmed by the user will be accessed by the menu program from the Input Quantity Program to be stored in a vector so that every time a user wants to order other food items he will just click another button and repeat the process.</p>
  
  <p>Now I've coded the most part and got everything working except one thing,the value returned by the Input Quantity Program has this delay thing.  </p>
  
  <p>This is what I do step by step:  </p>
  
  <p>1)Click a food item in Menu,it opens the Input Quantity window.<br>
  2)I input the number I want,it displayed in the text box correctly.<br>
  3)I pressed confirm which will do 3 things,first it stores the value of the text field to a variable,second it will call the dispose() method and third a print statement showing the value of the variable(for testing purposes).<br>
  4)The menu program then checks if the user has already pressed the Confirm button in the Input program,if true it shall call a method in the Input program called getQuantity() which returns the value of the variable 'quantity' and store it in the vector.<br>
  5)After which executes another print statement to check if the passed value is correct and then calls the method print() to show the ordered item name and it's recorded quantity.  </p>
  
  <p>Here are the screenshots of the GUI and the code will be below it.</p>
  
  <p><img src="https://i.stack.imgur.com/sTzph.png" alt="MENU GUI"><br>
  <img src="https://i.stack.imgur.com/fkDQz.png" alt="1st order">
  <img src="https://i.stack.imgur.com/BYrWB.png" alt="last order"></p>
  
  <p>ActionPerformed method of the CONFIRM BUTTON in the Input Quantity Program:  </p>
  
  <pre><code>private void ConfirmButtonActionPerformed(java.awt.event.ActionEvent evt) {                                              
      // TODO add your handling code here:
      confirmed = true;
      q= textField.getText().toString();
      quantity =Integer.parseInt(q) ;
      System.out.println("getQTY method inside Input Quantity Interface:" +getQuantity());
      System.out.println("Quantity from confirmButton in Input Quantity Interface actionPerformed: "+quantity);
  
      //getQuantity();
  }                            
  </code></pre>
  
  <p>ACTION LISTENER CLASS of the MENU ITEM BUTTONS in MENU PROGRAM which does step 2 above:  </p>
  
  <pre><code>class f implements ActionListener {
      @Override
      public void actionPerformed(ActionEvent e) 
      {
           inputGUI.setVisible(true);
           int  q =0;
  
            q=inputGUI.getQuantity(); //call method to get value from Input Program
  
            System.out.println("Quantity inside Menu actionperformed from AskQuantity interface: "+q);
  
           orderedQuantity.add(q); //int vector
           textArea.append("\n"+e.getActionCommand()+"\t"+ q);
           orderedItems.add(e.getActionCommand());  //String vector
           print();
           /*
           System.out.println("Enter QTY: ");
           int qty = in.nextInt();
           orderedQuantity.add(qty);
           print();*/
     }
  </code></pre>
  
  <p>Here are screenshots of the print statements in the console:<br>
  Here I first ordered Pumpkin Soup,I entered a quantity of 1<br>
  <img src="https://i.stack.imgur.com/GMlLc.jpg" alt="1st Order">  </p>
  
  <p>Here I ordered seafood marinara and entered a quantity of 2<br>
  <img src="https://i.stack.imgur.com/OoSiZ.jpg" alt="2nd order"></p>
  
  <p>Here I ordered the last item,pan fried salmon and entered a quantity of 3  </p>
  
  <p><img src="https://i.stack.imgur.com/cX28B.jpg" alt="enter image description here">  </p>
  
  <p>As you can see the first recorded quantity is 0 for the first item I ordered then when I added another item,the quantity of the first item gets recorded but the 2nd item's quantity is not recorded..same goes after the third item... and the quantity of the 3rd item is not recorded even if the program terminates :(  </p>
  
  <p>How can I solve this problem?</p>