Solved

closing  child window from a frame

Posted on 2001-08-06
1
291 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
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Increment alphanumeric sequence 6 80
allStar challenge 1 43
wordappend challenge 8 86
wordmultiple challenge 12 90
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…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now