Java – Show Confirmation Box Using JOptionPane

Working on Java Swing recently. The following example shows you how to create confirmation box.

import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class ConfirmPopUps {

  public static void main(String[] a) {
    JFrame frame = new JFrame();
    int result = JOptionPane.showConfirmDialog(frame, "Continue?");

    if (JOptionPane.YES_OPTION == result) {
      // YES
    } else if (JOptionPane.NO_OPTION == result) {
      // NO
    } else {
      // CANCEL
    }
  }
}

 

Done =)

Reference: Java2s – JOptionPane Confirm Pop-Ups

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.