As someone completely new to Java and Swing, I had the same problem; I was opening a new JFrame with a button, and then when I closed it, both JFrames would disappear. This post helped me to realise I had confused classes with instances. When pushing the button, I was setting the class template of my new JFrame as visible,
SecondFrame.setVisible(true);
and trying to set DISPOSE_ON_CLOSE within the class itself
when in fact when pushing the button I should have made
secondFrame secondframe = new secondFrame();
secondframe.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
secondframe.setVisible(true);
I'm happy that there are experienced people who post on boards like this...I was actually having trouble with this for ages