Reputation: 165
I'm writing java applet. I want to to open a new Frame with content actually stored in my Applet. I'm opening new Frame through the Button:
openInNew.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(ActionEvent e)
{
createDialog();
}
});
//this Function retrieves Frame for applet
public Frame getParentFrame( Component child )
{
Container c = child.getParent();
while ( c != null )
{
if ( c instanceof Frame )
{
return ( Frame ) c;
}
c = c.getParent();
}
return null;
}
private void createDialog()
{
Frame f=getParentFrame(openInNew); //openInNew is a button to Open a JDialog
frame = new AppletFrame("NEW FRAME",jContentPane);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
Here is the constructor for AppletFrame
:
public AppletFrame(String string, JPanel jContentPane, Frame f) {
super(f,string);
this.setContentPane(jContentPane);
this.setSize(790, 650);
this.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
removeAll();
FileListViewer.destroyFrame();
}
});
}
public static void destroyFrame()
{
jContentPane= (JPanel) frame.getContentPane();
jContentPane.repaint(); /*this one should repaint the Applet View, but the result
* is still the same. jContentPane is not null,
* it is filled with acutal components. */
jContentPane.setVisible(true);
frame.dispose();
frame.setVisible(false);
frame=null;
}
My problem is that jConentPane
is a reference, so immediately when I open my AppletFrame
object, there is nothing stored in my basic Applet Frame. I wanted to set again jContentPane
to FileListViewer
, but I can't refer to non-static method in static destroyFrame()
.
Upvotes: 1
Views: 579
Reputation: 109815
here no need to open a new JFrame or another Top Level Containers , use CardLayout instead
use JDialog if you want to move one Top Level Containers toFront/toBack
Upvotes: 3