1

I added a jDialog Swing Form to my project as in this image :

enter image description here

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 :

Object obj=sasirMdp.showDialog();

but the compiler tells me that there is no method named showDialog in my JDialog.

and when I added this method to the JDialog class :

ReturnValue showDialog() {
    setVisible(true);
    return result;
}

the copmiler tells me if I want to create the class ReturnValue.

Please if some one knows how to get that value from the JDialog, I'll be thankful.

Aimad Majdou
  • 563
  • 4
  • 13
  • 22

2 Answers2

2

I seems to me that you are mixing up JDialog and JOptionPane. You should read How to Make Dialogs. It is a great introduction to dialogs with swing.

1

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");
}
}
Mackie
  • 186
  • 9