GUIインスタンスから戻り値を取得したい GUIを作成するために実行するコード:
JFrame frame = new JFrame();
frame.getContentPane().add(new ChatPopup());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
私の GUI (ChatPopUp コードは次のとおりです。
public class ChatPopup extends javax.swing.JPanel {
private JButton cancelButton;
private JTextField textFieldchatRoomName;
private JLabel jLabel1;
private JButton okButton;
public ChatPopup() {
    super();
    initGUI();
}
private void initGUI() {
    try {
        this.setPreferredSize(new java.awt.Dimension(294, 85));
        {
            jLabel1 = new JLabel();
            this.add(jLabel1);
            jLabel1.setText("Please enter the new chat room name:");
        }
        {
            textFieldchatRoomName = new JTextField();
            this.add(textFieldchatRoomName);
            textFieldchatRoomName.setPreferredSize(new java.awt.Dimension(263, 22));
        }
        {
            cancelButton = new JButton();
            this.add(cancelButton);
            cancelButton.setText("Cancel");
            cancelButton.setPreferredSize(new java.awt.Dimension(84, 22));
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    System.out.println("Cancel PRESSED");
                }
            });
        }
        {
            okButton = new JButton();
            this.add(okButton);
            okButton.setText("Ok");
            okButton.setPreferredSize(new java.awt.Dimension(60, 22));
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    System.out.println("OK PRESSED");
                }
            });
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
}
これは非常にシンプルな GUI で、テキスト フィールドと 2 つのボタン ([OK]、[Chancel]) があります。「OK」をクリックすると、textField の値が、GUI インスタンスが最初に実行されたクラスに送信されます。
これを行う方法はありますか??