JOptionPane showConfirmDialog with YES_NO_OPTION and ImageIcon

Show a message and get a conformation (like Ok/Cancel).The showConfirmDialog return integers to indicate which button the user choose.

For the confirmation dialog, the return value can be one of the following :

OK_OPTION
CANCEL_OPTION
YES_OPTION
NO_OPTION
CLOSED_OPTION

Program

 

 

 

Program Source

import javax.swing.JOptionPane;
import javax.swing.ImageIcon;

public class Javaapp {
    
    public static void main(String[] args) {
        
        ImageIcon icon = new ImageIcon("WLive48x48.png");
        int returnValue=JOptionPane.showConfirmDialog(null,
                                                      "Activate Windows Now",
                                                      "Windows Activation",
                                                      JOptionPane.YES_NO_OPTION,
                                                      JOptionPane.QUESTION_MESSAGE,
                                                      icon);
         if(returnValue == 0)
            JOptionPane.showMessageDialog(null,"Windows Activated Successfully");
         else if(returnValue == 1)
            JOptionPane.showMessageDialog(null,"Windows Activate Later");
         else if(returnValue == -1)
            JOptionPane.showMessageDialog(null,"ConfirmDialog Closed");
    }     
}

Leave a Comment