MDI and Internal Frames

In my MDI Application, I have 2 different subclasses of InternalFrame

public class InternalFrame1 extends JInternalFrame

and

public class InternalFrame2 extends JInternalFrame

in my MDI class, i have a JDesktopPane called desktop and the following code:

InternalFrame1 frame=new InternalFrame1();

frame.setVisible(true);

desktop.add(frame);

try {

frame.setSelected(true);

} catch(java.beans.PropertyVetoException e){}

now, in InternalFrame1, when the user hits a button, i want to launch InternalFrame2. my problem is that i dont have a reference to the desktop object to add the InternalFrame2 object to the MDI frame.

is there a way to get the reference?

[764 byte] By [rapte] at [2007-9-26 2:09:11]
# 1

ok, i found one way to do this -

static JDesktopPane desktop;

and then in the InternalFrame1 actionEvent,

InternalFrame2 frame2=new InternalFrame2();

frame2.setVisible(true);

MDIApp.desktop.add(frame);

try {

frame2.setSelected(true);

}

is this ok, or is there a better way to do this?

rapte at 2007-6-29 8:58:36 > top of Java-index,Archived Forums,Java Programming...
# 2

Why can't you just use the desktop to add the 2nd internalFrame? When you press the button you make one visible and the other invisible.

You could pass a desktop reference to the 2nd internalFrame. Doing it the other way would be much more simple though.

[code]

public class JInternalFrame2 extends JInternalFrame

{

JDesktopPane desktop;

public JInternalFrame2(JDesktopPane p)

{

this.desktop = p;

desktop.add(this);

}

}

Hoju at 2007-6-29 8:58:36 > top of Java-index,Archived Forums,Java Programming...