Solved

closing  child window from a frame

Posted on 2001-08-06
1
297 Views
Last Modified: 2012-05-04

hi,

I have a frame.In this frame I have a pop up menu
when the user selects "create" option from the pop up menu
I display another frame to create something

The problem is when I close the main frame I want to
dispose this second  frame

How do I do this
I tried doing this

f.addWindowListener(new WindowAdapter ()
    {
         Window [] childWindows = null;
         public void windowClosing(WindowEvent event)
         {

           System.out.println("in window closing event");

           childWindows = f.getOwnedWindows();
           System.out.println("childWindows" + childWindows.length );

           for(int i=0;i<childWindows.length;i++)
           {
          System.out.println("destroy child window");
          childWindows[i].setVisible(false);
          String name = childWindows[i].getName();
          System.out.println("name" + name);
          childWindows[i].dispose();
           }

         }

    });

This does not work.
How do I do this.




 
0
Comment
Question by:sanjay_thakur
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
dviji earned 20 total points
ID: 6357450
Two ways,

1. In your parent window class keep track of your child windws, in your child window if you close the child window remove its refrence from parent and at the same time if you want to close the parent in the windowClosed() method (You should implement WindowListener)disposee all of its child.


2. In the Frame class use getFrames() class and dispose all the Frames in the parent's windowClosed() method (You should implement WindowListener).

------

Instead of creating child frames if you create Dialog and associate that dialog to your Parent frame. So if you close the child dialogs the Jvm close all of its childs().

...dviji
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question