[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Dialogs and parent frames

When you create a java.awt.Dialog you have to pass a Frame object to identify the Dialog's parent.  The questions are:

1. Can that parent Frame be null? and

2. If not, how to create a Dialog in an Applet where there may be no Frame object?

I am using JDK 1.1.x
0
msmolyak
Asked:
msmolyak
  • 2
1 Solution
 
XLoggerCommented:
1. No. Try, but don't forget to catch "parent null exception" :)

2. Create dummy frame object, without showing it:
For example,

public class Test extends Applet {
      Button b;
      
      public void init () {
            add( b = new Button( "Test" ) );
      }
      
      public boolean handleEvent( Event e ) {
            if( e.id == Event.ACTION_EVENT && e.target == b ) {
                  new TestDialog( new Frame () );
                  return true;
            }
            
            return false;
      }
}

class TestDialog extends Dialog {
      Button bnClose;

      public TestDialog( Frame f ) {
            super( f, "TestDialog", true );
                //...
        }
}

3. Be careful using JDK 1.1.* when writing applets, it's still not supported by most of browsers.
0
 
msmolyakAuthor Commented:
Creating a fake frame is fine. But if a fake frame would do why would not no frame work? Do you know how the Dialog uses parent frame and why it throws an exception if the parent is null?
0
 
XLoggerCommented:
First, dialog or any non-frame window coordinates are relative to its parent; also when parent window is disposed, it causes all its child windows to be disposed. But the most crucial argument to use non-null frame is following lines in Dialog constructor:

  if (parent == null) {
    throw new IllegalArgumentException("null parent frame");
  }

There are source code for all classes from java.* packages.
Sometimes it really helps to understand program behavior.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now