如何将值从JInternalFrame传递给JDialog

时间:2014-04-25 05:37:09

标签: java swing jdialog jinternalframe

我只是想知道如何将JInternalFrame之类的字符串传递给JDialogJDialog是子表单,JInternalFrame是父表单。如果你能告诉我一个简单的例子。

这是我的代码,我想将ID从ProductDetails传递给AddQuantity,我试图使用静态但它不能正常工作

public class ProductDetails extends javax.swing.JInternalFrame {
String id;
    public ProductDetails() throws Exception {
        initComponents();
}
//This is a button to go to JDialog
 private void btnAddQuantityActionPerformed(java.awt.event.ActionEvent evt) {                                               
        id = txtID.getText();
        AddQuantity aq = new AddQuantity(null, true);
        aq.setLocationRelativeTo(aq);
        aq.setVisible(true);
}
}


public class AddQuantity extends javax.swing.JDialog {
    ProductDetails pd;
    public AddQuantity(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        //i use showMessage to show result but it show me nothing 
        JOptionPane.showMessageDialog(this, pd.id);
        txtCurrentID.setText(pd.id);
    }
    }

2 个答案:

答案 0 :(得分:0)

根据我的说法没有特定的方法可以做到这一点,但你可以做一件事,宣告数据静态,你也可以访问该对话框中的静态东西。所以你可以在那里展示:)

其他的是Make方法带输入参数Dialog。

答案 1 :(得分:0)

  • JFrame作为JDialog的所有者传递。
  • 致电JDialog#getOwner()以获取所有者
  • 从所有者
  • 获取所需的值