私の方法をクールな方法で説明できるかどうかわかりません... ユーザーからその情報を取得しようとしている JDialog から productPrice と amount が必要だとしましょう。JFrame からそれを呼び出す必要があります。
JDialog 内で、productPrice と ammount を public 非静的グローバル変数として宣言します。
public float productPrice;
public int amount;
* これは、ダイアログのクラス グローバル スコープ内に入ります。
これらの行を JDialog コンストラクターに追加して、モダリティを確保します
super((java.awt.Frame) null, true);
setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
* これは、ダイアログのクラス コンストラクター内で行われます
このようなことを呼び出すときに、JDialogのクラス名が「MyJDialog」であるとしましょう
MyJDialog question = new MyJDialog();
MyJDialog.setVisible(true);
// Application thread will stop here until MyJDialog calls dispose();
// this is an effect of modality
//
// When question calls for dispose(), it will leave the screen,
// but its global values will still be accessible.
float myTotalCostVar = question.productPrice * question.ammount;
// this is acceptable.
// You can also create public getter function inside the JDialog class,
// its safer and its a good practice.
* これは、JFrame 内の任意の関数に入り、JDialog を呼び出して情報を取得します。