[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Dialogs and parent frames

Posted on 1998-01-15
3
Medium Priority
?
275 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
[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
  • 2
3 Comments
 

Accepted Solution

by:
XLogger earned 120 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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