1

この画像のように、jDialog Swing フォームをプロジェクトに追加しました。

ここに画像の説明を入力

そして今、このJDialogを閉じるときに、そのjtextFieldから親JFrameへの値を取得したいので、それについてグーグルで調べたところ、これが見つかりました:

Object obj=sasirMdp.showDialog();

showDialogしかし、コンパイラは、私の JDialog に名前が付けられたメソッドがないことを教えてくれます。

このメソッドを JDialog クラスに追加すると、次のようになります。

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

コピーラーは、クラスを作成するかどうかを教えてくれますReturnValue

からその値を取得する方法を知っている人がいれば、JDialog感謝します。

4

2 に答える 2

2

JDialog と JOptionPane を混同しているようです。How to Make Dialogs を読んでください。これは、swing を使用したダイアログの優れた入門書です。

于 2013-06-09T10:20:43.130 に答える
1

このようなものが欲しいですか?

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");
}
}
于 2013-06-20T14:32:23.753 に答える