[3283] in java-interest

home help back first fref pref prev next nref lref last post

Re: dialogs, applets, and frames

daemon@ATHENA.MIT.EDU (Ed Anuff)
Mon Nov 6 10:14:52 1995

Date: Sun, 5 Nov 1995 21:31:19 -0800
To: java-interest@java.sun.com
From: edanuff@protagonist.com (Ed Anuff)

>> To create a new Dialog, you have to have a Frame argument for that
>> dialog to attach to.  Does this mean I can only have dialogs for
>> actual popup windows -- not applets?  Applets aren't frames.
>
>I believe that you should be able to follow your parent chain up until
>you get a null.  The last parent you get before the null should be a
>top level frame that you can associate your dialog with.

This is what I use to find a component's frame.  It works in appletviewer
and Netscape 2.0b2, but I don't know whether there is always a top level
frame.

class ComponentUtil {
        public static Frame getFrame(Component theComponent) {
                Component currParent = theComponent;
                Frame theFrame = null;

                while (currParent != null) {
                        if (currParent instanceof Frame) {
                                theFrame = (Frame)currParent;
                                break;
                        }
                        currParent = currParent.getParent();
                }

                return theFrame;
        }
}

You can then use something like this to find the frame and create a dialog:

        Frame theFrame = ComponentUtil.getFrame(this);
        FileDialog theDialog = new FileDialog(theFrame, "test");
        theDialog.show();

Hope this helps,

Ed



Ed Anuff
Protagonist Interactive
edanuff@protagonist.com
http://www.protagonist.com/


-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post