title: How do I create JTextFields on a popup when I select JRadioButton in Java Swing
body: <p>I am new to Java Swing.</p>
  
  <p>When I select a JRadioButton it should pop up with JTextFields where the user can enter details like name, age, etc. Please let me know if anything is wrong.</p>
  
  <p>Can anyone help me out for the below sample code?</p>
  
  <pre><code>import java.awt.EventQueue;
  import java.awt.GridLayout;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  
  import javax.swing.ButtonGroup;
  import javax.swing.JDialog;
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  import javax.swing.JRadioButton;
  
  public class DialogTest extends JDialog implements ActionListener {
  
      private static final String TITLE = "Season Test";
  
      private enum Season {
          WINTER("Winter"), SPRING("Spring");
          private JRadioButton button;
          private Season(String title) {
              this.button = new JRadioButton(title);
          }
      }
  
      private DialogTest(JFrame frame, String title) {
          super(frame, title);
          JPanel radioPanel = new JPanel();
          radioPanel.setSize(800,800);
          radioPanel.setLayout(new GridLayout(3, 1));
          ButtonGroup group = new ButtonGroup();
  
          for (Season s : Season.values()) {
              group.add(s.button);
              radioPanel.add(s.button);
              s.button.addActionListener(this);
          }
          Season.SPRING.button.setSelected(true);
          this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
          this.add(radioPanel);
          this.pack();
          this.setLocationRelativeTo(frame);
          this.setVisible(true);
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
          JRadioButton b = (JRadioButton) e.getSource();
          JOptionPane.showMessageDialog(null, "You chose: " + b.getText());
      }
  
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
  
              @Override
              public void run() {
                  new DialogTest(null, TITLE);
              }
          });
      }
  }
  </code></pre>