My program starts with a picture with a textfield in a JFrame. I want when the user types start it closes the picture JFrame and opens another JFrame with the main program. I’ve tried
processEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING));
on the Image frame but it closes all the windows.
The method
JFrame.setVisiblecan be used to hide or display the JFrame based on the arguments, whileJFrame.disposewill actually “destroy” the frame, by closing it and freeing up resources that it used. Here, you would callsetVisible(false)on the picture frame if you intend to reopen it, or calldispose()on the picture frame if you will not be opening it again, so your program can free some memory. Then you would callsetVisible(true)on the main frame to make it visible.