How to control iconifying and closing on multiple jframes from a main frame

Hi guys I have a problem.

I have an application that open four jframes in order to perform a simulation. If the user iconify one of these frames( or the main frame) everything have to be iconified. The same have to happen for deiconifing, closing, activating ecc.

What should happen is that any frame that have to be (i.e.) iconified, iconify itself and then ask to the main window to iconify everything else.

What actually happens is that nothing is moving, only the closing action is working fine (because i use a System.exit in that case).

Is too late for me to use a jinternalframe, because i have to change too many things.

What else i have to put in the methods to force them work? Thank you in advance.

//main window

publicvoid windowActivated(WindowEvent arg0){

//all the children windows are created at the same time

if(nord!=null && !attivi){

attivi=true;//to avoid stack overflow

nord.getWindowListeners()[0].windowActivated(arg0);

sud.getWindowListeners()[0].windowActivated(arg0);

ovest.getWindowListeners()[0].windowActivated(arg0);

est.getWindowListeners()[0].windowActivated(arg0);

}

//children

publicvoid windowActivated(WindowEvent arg0){

root.getWindowListeners()[0].windowActivated(arg0);

}

I tried also dispatchEvent but is not working.

[1881 byte] By [Turuzzua] at [2007-11-27 9:58:23]
# 1

seems to work OK like this

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

class Testing

{

public void buildGUI()

{

for(int x = 0; x < 4; x++)

{

CommonFrame cf = new CommonFrame();

cf.setBounds(x*200,100,100,100);

cf.setVisible(true);

}

}

public static void main(String[] args)

{

SwingUtilities.invokeLater(new Runnable(){

public void run(){

new Testing().buildGUI();

}

});

}

}

class CommonFrame extends JFrame

{

public CommonFrame()

{

super();

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

addWindowListener(new WindowAdapter(){

public void windowIconified(WindowEvent we){

Frame[] frames = getFrames();

for(int x = 0,y = frames.length; x < y; x++)

{

frames[x].setExtendedState(JFrame.ICONIFIED);

}

}

public void windowDeiconified(WindowEvent we){

Frame[] frames = getFrames();

for(int x = 0,y = frames.length; x < y; x++)

{

frames[x].setExtendedState(JFrame.NORMAL);

}

}

});

}

}

Michael_Dunna at 2007-7-13 0:29:03 > top of Java-index,Desktop,Core GUI APIs...
# 2
Thank you, now works fine.
Turuzzua at 2007-7-13 0:29:03 > top of Java-index,Desktop,Core GUI APIs...