Solved

Dialogs and parent frames

Posted on 1998-01-15
3
263 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

758 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

23 Experts available now in Live!

Get 1:1 Help Now