-2

For some time, I've been trying to open a different JFrame AdminHome but it doesn't open. Even after I made a method of the JFrame

AdminHome hmscrn = new AdminHome();

All it does is to close my already completed frame and end the program completely instead of opening the home page

private void addBttnActionPerformed(java.awt.event.ActionEvent evt) {                                        
    try{
    String sql = "insert into maintainsite (siteID,country,state,city,revenue,date,capacity) values (?,?,?,?,?,?,?)";
    pst=conn.prepareStatement(sql);
    pst.setString(1, (String) siteID.getSelectedItem());
    pst.setString(2, (String) country.getSelectedItem());
    pst.setString(3, (String) state.getSelectedItem());
    pst.setString(4, (String) city.getSelectedItem());
    pst.setString(5, revenuelb.getText());
    pst.setString(6, ((JTextField) date.getDateEditor().getUiComponent()).getText());
    pst.setString(7, capacitylb.getText());


    pst.execute();
      int replying = JOptionPane.showConfirmDialog(null, "information saved! return to home page?","successful", JOptionPane.YES_NO_OPTION);
    if (replying == JOptionPane.YES_OPTION) {
      JOptionPane.showMessageDialog(null, "got it!");
      close();
    AdminHome hmscrn = new AdminHome();
    hmscrn.setVisible(true);
    }
      else {
       JOptionPane.showMessageDialog(null, "close program!");

    close();
    }


    }
    catch(Exception e){JOptionPane.showMessageDialog(null, "please complete your selection and try again");}
} 
Frakcool
  • 10,915
  • 9
  • 50
  • 89
  • What does your close() method look like? If it includes System.exit(), then your program will terminate at that point. – FredK Jun 21 '16 at 14:06
  • 1
    The purpose of an exception is to tell you what has gone wrong. Instead of ignoring it, try `e.printStackTrace();` in your catch block. – VGR Jun 21 '16 at 14:40
  • 1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556) 2) For better help sooner, post a [MCVE] or [Short, Self Contained, Correct Example](http://www.sscce.org/). Hard code some data to replace the DB. – Andrew Thompson Jun 22 '16 at 02:07

1 Answers1

-2

I've seen my mistake.

On your actual JFrame options in the properties aspect you have to change defaultCloseOperation from EXIT ON CLOSE to DISPOSE_ON_CLOSE.

I hope I also kinda saved someone else going through the same.

Frakcool
  • 10,915
  • 9
  • 50
  • 89
  • Next time please provide a [mcve] instead of a code snippet, it will give us more information, and you will get more, faster and better answers that way. – Frakcool Jun 21 '16 at 15:57
  • 2
    No your problem is that you're trying to use a JFrame where a JDialog should be used. An application should have only one open JFrame and should avoid swapping JFrames. – Hovercraft Full Of Eels Jun 21 '16 at 16:28