Dialogs in Applets

A

Andrew Thompson

Dialogs want Frame not Panels from which Applet is derived. What did
Sun intend for you to do? Are you supposed to search for a parent
frame of Applet? create one?

<sscce>
import java.awt.*;

public class DialogApplet extends java.applet.Applet {

public void init() {
Frame[] frames = Frame.getFrames();
Dialog dialog = new Dialog( frames[0] );
dialog.add( new Label("Blah!") );
dialog.pack();
dialog.setVisible(true);
}
}
</sscce>

HTH
 
A

Andrew Thompson

Dialogs want Frame not Panels from which Applet is derived. What did
Sun intend for you to do? Are you supposed to search for a parent
frame of Applet? create one?

<sscce>
import java.awt.*;

public class DialogApplet extends java.applet.Applet {

public void init() {
Frame[] frames = Frame.getFrames();

Which will not work for 1.1, it was introduced in 1.2 (damnit!)

However, this seems to work[1]..

<sscce>
import java.awt.*;

public class DialogApplet extends java.applet.Applet {

public void init() {
Dialog dialog = new Dialog( new Frame() );
dialog.add( new Label("Blah!") );
dialog.pack();
dialog.setVisible(true);
}
}
</sscce>

[1] Checked in ..
MSVM 1.1.4 (IE) and
Symantec VM 1.1.5 (Netscape Nav. 4.78)
 
A

Andrew Thompson

Will work, but will not make a "child" of the browser Frame. Which
means it will not hide when the browser hides, will not inherit its
icon etc.

Riiight. That *could* explain the strange
behaviour I'd noted in a Java 1.1 splash screen.

I'll have to revisit the code to investigate further.
 
T

Tor Iver Wilhelmsen

Andrew Thompson said:
Dialog dialog = new Dialog( new Frame() );

Will work, but will not make a "child" of the browser Frame. Which
means it will not hide when the browser hides, will not inherit its
icon etc.
 
T

Tor Iver Wilhelmsen

Andrew Thompson said:
I'll have to revisit the code to investigate further.

The best way is to iterate on getParent() until you hit a Frame or
null.
 
P

Pete Barrett

Dialogs want Frame not Panels from which Applet is derived. What did
Sun intend for you to do? Are you supposed to search for a parent
frame of Applet? create one?

If you're using Swing (and a JDialog is derived from Dialog, so is not
a JAnythingElse) there's a SwingUtilities method to search for the
closest parent which is an instance of a particular class (Frame, in
this case).

Pete Barrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top