title: Java program exits when I click OK button in JOptionPane.showMessageDialog
body: <p>when I click the <strong>OK</strong> button in second.java program, the program exit the program. I want it not to exit (since there is a thread running). I tried removing <strong>setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)</strong>. </p>
  
  <p><a href="https://i.stack.imgur.com/NALZE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NALZE.jpg" alt="alt text"></a>
  </p>
  
  <hr>
  
  <p>CODE</p>
  
  <hr>
  
  <pre><code>import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import javax.swing.JButton;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JOptionPane;
  import javax.swing.JTextField;
  
  public class second extends JFrame implements ActionListener {
  
  JLabel enterName;
  JTextField name;
  JButton click;
  String storeName;
  
  public second(){
  
      setLayout(null);
      setSize(300,250);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      enterName = new JLabel("Enter Your Name: ");
      click = new JButton("Click");
      name = new JTextField();
      enterName.setBounds(60,30,120,30);
      name.setBounds(80,60,130,30);
      click.setBounds(100,190,60,30);
      click.addActionListener(this);
      add(click);
      add(name);
      add(enterName);
  
  }
  
  public void actionPerformed(ActionEvent e) {
  
      if(e.getSource() == click) {
  
          storeName = name.getText();
          JOptionPane.showMessageDialog(null, "Hello" + storeName);
          System.exit(0);
      }
  }
  
  public static void main(String args[]){
  
      second s = new second();
      s.setVisible(true);
  }
  }
  </code></pre>
  
  <hr>
  
  <p>Many Thanks</p>