I am making a project. I need about 5 JFrame but all are interrelated.
this is my main frame code
public void mframe(boolean b) //function for main JFrame...
{
JFrame.setDefaultLookAndFeelDecorated(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
main m=new main(); // main constructor call ...
JFrame frame = new JFrame(" Demo Project submited by: Ankit ");
frame.setJMenuBar(m.menuBar); // set JMenueBar in JFrame frame...
try { // try to add a background pic and icon
frame.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("pics/index.jpg")))));
frame.setIconImage(ImageIO.read(new File("pics/girl.png")));
} catch (IOException e) {
e.printStackTrace();
}
frame.setLayout(null);
frame.setOpacity(0.88f);
frame.setSize(510,420);
frame.setResizable(false);
frame.setVisible(b);
if (!gd.isWindowTranslucencySupported(TRANSLUCENT))
{
frame.setJMenuBar(m.menuBar);
frame.setVisible(b);
frame.setSize(500,400);
}
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String agr[])
{
main m = new main();
m.mframe(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==exit)
{
System.exit(0);
}
else if(e.getSource()==Ankit)
{
Contact c = new Contact();
c.cframe(true);
// dispose();
main m1 = new main();
m1.mframe(false);
}
}
and this is my second frame , contact frame code
public void cframe(boolean b)
{
JFrame.setDefaultLookAndFeelDecorated(true);
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice gd = ge.getDefaultScreenDevice();
Contact co=new Contact();
JFrame cframe = new JFrame(" Ankit Ujlayan (b.tech IT) ");
try {
cframe.setContentPane(new JLabel(new ImageIcon(ImageIO.read(new File("pics/cont.jpg")))));
cframe.setIconImage(ImageIO.read(new File("pics/girl.png")));
} catch (IOException e) {
e.printStackTrace();
}
cframe.setLayout(null);
cframe.setOpacity(0.87f);
cframe.setSize(510,420);
cframe.setJMenuBar(co.cmenu);
cframe.setVisible(b);
cframe.setResizable(false);
cframe.add(co.p1);
cframe.add(co.p2);
cframe.add(co.p3);
//cframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String arg[])
{
//Contact c = new Contact();
//c.cframe(false);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==close)
{
System.exit(0);
}
if(e.getSource()==back)
{
main m=new main();
m.mframe(true);
//dispose();
Contact c1= new Contact();
c1.cframe(false); // I call cframe by passing Boolean "false"
}
}
I have try to dispose it many time and also google for it but I fail to dispose it .....