title: How to close previous jframe on the new open jframe
body: <p>I have a problem in disposing the two JFrames in one click of a button. I have a 2 JFrames(SUC_Forms and add_suc) when the button "ADD RECORDS" in SUC_Forms was click another new JFrame will show which is the add_suc jframe that contains textboxes for registration/filing. When i press ok to validate and insert all the data in the database, a JDialogbox will pop-up for a confirmation. Once I hit "Ok" both JFrames will dispose and then SUC_Forms-JFrame will show again containing the updated data. I have a trouble on how the current JFrames has an access to the previous and active JFrame. Can you pls help me to solve this problem? Thanks in advance..</p>
  
  <p>Heres my print screen.</p>
  
  <p><a href="https://i.stack.imgur.com/5aD1S.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5aD1S.png" alt="enter image description here"></a></p>
  
  <p>SUC_Forms Code:</p>
  
  <pre><code>    add_suc add = new add_suc();
      add.show();
  </code></pre>
  
  <p>add_suc Code:</p>
  
  <p>private void btn_okActionPerformed(java.awt.event.ActionEvent evt) {                                       </p>
  
  <pre><code>    int verify = JOptionPane.showConfirmDialog(rootPane,"Are you sure you want to add this record?","", JOptionPane.YES_NO_OPTION);
  
      if(verify == 0)
      {
  
         String moa_id = txt_id.getText();
         Object region = cmb_region.getSelectedItem();
         String holder = txt_holder.getText();
         String brgy = txt_brgy.getText();
         String municipality = txt_municipality.getText();
         String province = txt_province.getText();
         String president = txt_president.getText();
         Object month = cmb_month.getSelectedItem();
         Object day = cmb_day.getSelectedItem();
         String year = txt_year.getText();
         String area = txt_area.getText();
         String allotment = txt_allotment.getText();
         String activities = txt_activities.getText();
         String status = txt_status.getText();
         String fill = "";
  
         if(moa_id.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill Moa ID!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
  
         if(region.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please select region!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(holder.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill holder!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(brgy.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill barangay!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(municipality.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill municipality!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(province.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill province!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
          else if(president.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill president/representative!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
          else if(month.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please set the month of Date Approved field!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
  
         else if(day.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please set the date of Date Approved field!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(year.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please set the year of Date Approved field!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(area.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill area!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(allotment.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill allotment!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(activities.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill activities/roles!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
         else if(status.equals(fill))
         {
             JOptionPane.showMessageDialog(rootPane, "Please fill status!", "Message",JOptionPane.ERROR_MESSAGE,null);
         }
  
         else{
  
          try{
  
          st = con.createStatement();
  
          String query =  "insert into moa_suc values('"+moa_id+"','"+region+"','"+holder+"','"+brgy+"','"+municipality+"','"+province+"','"+president+"','"+month+"','"+day+"','"+year+"','"+area+"','"+allotment+"','"+activities+"','"+status+"')";
  
          st.executeUpdate(query);
  
          txt_id.setText("");
          cmb_region.setSelectedItem(0);
          txt_holder.setText("");
          txt_brgy.setText("");
          txt_municipality.setText("");
          txt_province.setText("");
          txt_president.setText("");
          cmb_month.setSelectedItem(0);
          cmb_day.setSelectedItem(0);
          txt_year.setText("");
          txt_area.setText("");
          txt_allotment.setText("");
          txt_activities.setText("");
          txt_status.setText("");
  
          JOptionPane.showMessageDialog(rootPane, "Successfully added to the record!", "Message",JOptionPane.INFORMATION_MESSAGE,null);
          this.dispose();
  
      }
      catch(SQLException err){
  
          System.out.println(err.toString());   
      }
  
       }
  
      }
      else
      {
          JOptionPane.showMessageDialog(rootPane, "Sorry! No data added in the record!", "Message",JOptionPane.INFORMATION_MESSAGE,null);
      }
  
  }
  </code></pre>