[英]Get a value from JDialog to the parent JFrame
我在我的项目中添加了一个jDialog Swing表单,如下图所示:
现在,当我关闭这个JDialog时,我希望从jtextField获取值到父JFrame,我用谷歌搜索它,我发现了这个:
Object obj=sasirMdp.showDialog();
但是编译器告诉我在我的JDialog中没有名为showDialog
方法。
当我将此方法添加到JDialog类时:
ReturnValue showDialog() {
setVisible(true);
return result;
}
copmiler告诉我是否要创建ReturnValue
类。
如果有人知道如何从JDialog
获得该值,我将非常感激。
我觉得你在混淆JDialog和JOptionPane。 您应该阅读如何制作对话框 。 这是对摆动对话的一个很好的介绍。
你想要这样的东西吗?
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.