frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(false); //you can't see me!
dispose(); //Destroy the JFrame object
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));