我只是想知道如何将JInternalFrame
之类的字符串传递给JDialog
。 JDialog
是子表单,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);
}
}
答案 0 :(得分:0)
根据我的说法没有特定的方法可以做到这一点,但你可以做一件事,宣告数据静态,你也可以访问该对话框中的静态东西。所以你可以在那里展示:)
其他的是Make方法带输入参数Dialog。
答案 1 :(得分:0)
JFrame
作为JDialog
的所有者传递。JDialog#getOwner()
以获取所有者