I am afraid that is not so. The output of this tiny program indicates
that
the JDialog is constructed before the constructor of JFrame is called:
No it doesn't.
class MyDialog extends javax.swing.JDialog
{
MyDialog(javax.swing.JFrame
a){System.out.println("MyDialog.constructor");}
}
class MyFrame extends javax.swing.JFrame
{
MyDialog mydialog=new MyDialog(this);
MyFrame(){super();System.out.println("MyFrame.constructor");}
public static void main(String[]a){new MyFrame();}
}
//output:
//MyDialog.constructor
//MyFrame.constructor
As I say, the initialiser for jdialog runs *immediately* after super()
returns. Your code prints "MyFrame.constructor" after super() returns, and
after the initialisers have run.
class MyDialog extends javax.swing.JDialog {
MyDialog(javax.swing.JFrame frame) {
System.out.println(
"MyDialog.constructor, frame.title: "+frame.getTitle()
);
}
}
class MyFrame extends javax.swing.JFrame {
private MyDialog mydialog = new MyDialog(this);
MyFrame() {
super(print("--- title ---"));
System.out.println("MyFrame.constructor, after super");
}
private static String print(String msg) {
System.out.println("Print: "+msg);
return msg;
}
public static void main(String[] args){
new MyFrame();
}
}
$ java MyFrame
Print: --- title ---
MyDialog.constructor, frame.title: --- title ---
MyFrame.constructor, after super
The title property is set in the JFrame constructor. The MyDialog
constructor reads that property, so must have printed the message after
the JFrame constructor ran.