Dialogs require a parent Frame in their constructor, but Applets inherit from Panel (and then Container), not Frame. Specifically, in JDK 1.5, Panel's inheritance tree is:
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
Now I had heard somewhere that you could try calling the Applet's getParent() method recursively until you reached the parent Frame, but this should be impossible. But it isn't.
Namely, the following bit of code works fine:
Container parent = this.getParent();
while ( !(parent instanceof Frame) && parent != null ) {
parent = parent.getParent();
}
Frame pFrame = (Frame)parent;
BJConfirmDialog d = new BJConfirmDialog(pFrame, "Test", "Click OK", 100, 100, 100, 100);
BJConfirmDialog is a custom class I have for displaying a standard confirmation dialog with a message, an OK and cancel button. This code works.
Now riddle me this - if Applet is extended from the tree listed above, then where is the Frame in there coming from??
I suppose I should just be thankful it works. I'm just curious as to WHY it works. *scratches head*
=========================Buildium. Codium. Fragium.http://www.aklabs.net/=========================