I am creating a Java Application using netBeans and Swing Gui Builder. I am trying to create an application that closes the current window and opens a new one when a selection is made from the view menu. What would be the best way to do this?
EDIT: I am trying to create a desktop application.
If you only have 2 windows that you want to swap between, it may be easiest to just use JFrame.setVisible() to swap between the two.
This doesn’t actually close frame1–it just hides it and pops frame 2 into visibility.
If you are writing a program with many potential windows and you want to actually “destroy” the window (thus freeing up the extra memory it takes up) you need to call JFrame.dispose();