how to check if window is open?

I am trying to create a button that will launch a new window. But I want it to check to make sure that the window trying to be launched is not already open. I am having issues I believe because the button is in one java file (class) and the window to be opened is a JFrame implemented in a different class.

ActionListener prefListener =new ActionListener(){

publicvoid actionPerformed(ActionEvent e){

System.out.println("Loading prefs...");

WindowPrefs WindowPrefs;

WindowPrefs =new WindowPrefs();

if (WindowPrefs.isVisible() !=true)

{

WindowPrefs.setVisible(true);

}

}

};

Currently, it will just open a new instance of the window over the old one and the windows will stack to infinity if you keep pressing the "launch window" button. Should I be using a listener

Can sombeody help?

[1286 byte] By [jay2coola] at [2007-11-26 20:01:32]
# 1

The windows are stacking to infinity because you are instantiating a new WindowPrefs each time you click the Launch button.

Try keeping your WindowPrefs variable on the class level so that you only have one instance.

private WindowPrefs windowPrefs = new WindowPrefs();

Try this instead in your action listener...

ActionListener prefListener = new ActionListener() {

public void actionPerformed(ActionEvent e) {

System.out.println("Loading prefs...");

if (windowPrefs.isVisible() != true)

{

windowPrefs.setVisible(true);

}

}

};

Message was edited by:

maple_shaft

maple_shafta at 2007-7-9 23:00:08 > top of Java-index,Java Essentials,Java Programming...
# 2
thanks. that seems to solve the issue.
jay2coola at 2007-7-9 23:00:08 > top of Java-index,Java Essentials,Java Programming...