[英]Get a value from JDialog to the parent JFrame
I added a jDialog Swing Form to my project as in this image : 我在我的项目中添加了一个jDialog Swing表单,如下图所示:
and now I want to get the value from that jtextField to the parent JFrame when I close this JDialog, I googled about it and I found this : 现在,当我关闭这个JDialog时,我希望从jtextField获取值到父JFrame,我用谷歌搜索它,我发现了这个:
Object obj=sasirMdp.showDialog();
but the compiler tells me that there is no method named showDialog
in my JDialog. 但是编译器告诉我在我的JDialog中没有名为
showDialog
方法。
and when I added this method to the JDialog class : 当我将此方法添加到JDialog类时:
ReturnValue showDialog() {
setVisible(true);
return result;
}
the copmiler tells me if I want to create the class ReturnValue
. copmiler告诉我是否要创建
ReturnValue
类。
Please if some one knows how to get that value from the JDialog
, I'll be thankful. 如果有人知道如何从
JDialog
获得该值,我将非常感激。
I seems to me that you are mixing up JDialog and JOptionPane. 我觉得你在混淆JDialog和JOptionPane。 You should read How to Make Dialogs .
您应该阅读如何制作对话框 。 It is a great introduction to dialogs with swing.
这是对摆动对话的一个很好的介绍。
Do you want something like this? 你想要这样的东西吗?
public class TestJDialog extends JFrame implements ActionListener
{
private JLabel l;
public TestJDialog(String title)
{
super(title);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
this.setLayout(new GridLayout(0,1));
JButton b = new JButton("Input Dialog");
b.addActionListener(this);
this.add(b);
l = new JLabel();
this.add(l);
setSize(300, 100);
setVisible(true);
}
public void actionPerformed(ActionEvent evt)
{
String s = evt.getActionCommand();
String input = JOptionPane.showInputDialog(this,
"Saisissez votre mot de passé:",
s,
JOptionPane.QUESTION_MESSAGE);
l.setText("Mot passé: " + input);
}
public static void main(String[] args)
{
new TestJDialog("Example");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.