public class T {
public static void main(String[] args) {
JPanel p = new JPanel(new GridLayout(0, 1, 0, 5));
JTextField tf1 = new JTextField(10);
JTextField tf2 = new JTextField(10);
p.add(new JLabel("Name:"));
p.add(tf1);
p.add(new JLabel("Age:"));
p.add(tf2);
int r = JOptionPane.showConfirmDialog(null, p, "Test",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
if (r == JOptionPane.OK_OPTION) {
System.out.println("Name: " + tf1.getText());
System.out.println("Age: " + tf2.getText());
}
}
}