I'm relatively new to Java programming and might have missed something obvious so bear with me.
I'm creating a program that uses the Swing API with JDesktopPane to create a GUI. On the main screen is a button that says 'New Window'. The user clicks it and a new JInternalFrame is instantiated and added to the JDesktopPane. As in the following, simplified, method:
protected void createNewWindow(JPanel panel) {
JInternalFrame fooFrame = new JInternalFrame();
fooFrame.setContentPane(panel);
desktop.add(fooFrame);
}
My question is this. Say the user clicks the button ten times. Ten JInternalFrames are created. All of them are method variables so they have the same name.
What happens to these old fooFrame variables? Does the garbage collector come and destroy them at any stage? I wouldn't have thought anything is still holding a reference to them. Is there any way to access any of these old fooFrames? Say I wanted to change the text colour on a JPanel on the fourth out of ten fooFrames. Any way to do this?
I know this is a very stupid way to do things, and it's simple to just create a JInternalFrame instance variable, possibly an array, to instantiate in the method and add to the JDesktopPane. My question was more out of curiosity than anything.