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
Solved

Dialogs and parent frames

Posted on 1998-01-15
3
269 Views
Last Modified: 2008-03-06
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
Comment
Question by:msmolyak
  • 2
3 Comments
 

Accepted Solution

by:
XLogger earned 30 total points
ID: 1232233
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
 
LVL 5

Author Comment

by:msmolyak
ID: 1232234
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
 

Expert Comment

by:XLogger
ID: 1232235
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
The viewer will learn how to implement Singleton Design Pattern in Java.

829 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