?
Solved

Dialogs and parent frames

Posted on 1998-01-15
3
Medium Priority
?
274 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month15 days, 15 hours left to enroll

743 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