JOptionPane showInputDialog with Selection String

showInputDialog()

Show a message and get one line of user input. The input dialog has an additional component for user input. This can be a text field into which the user can type an arbitrary string.

Program

 

 

 

Program Source

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

public class Javaapp {
    
    public static void main(String[] args) {
        
        ImageIcon icon = new ImageIcon("flag.png");
        String countrys[]={"India","America","Australia"};
        String name=(String)JOptionPane.showInputDialog(null,
                                                 "Country name", 
                                                 "Country Confirmation", 
                                                 JOptionPane.PLAIN_MESSAGE,
                                                 icon, 
                                                 countrys, 
                                                 countrys[0]);
        if(name == countrys[0])
        {
            icon = new ImageIcon("India.png");
            JOptionPane.showMessageDialog(null,
                                          "Ok Done",
                                          "Country Confirmation",
                                          JOptionPane.INFORMATION_MESSAGE,
                                          icon);
        }
        else if(name == countrys[1])
        {
            icon = new ImageIcon("America.png");
            JOptionPane.showMessageDialog(null,
                                          "Ok Done",
                                          "Country Confirmation",
                                          JOptionPane.INFORMATION_MESSAGE,
                                          icon);
        }
        else if(name == countrys[2])
        {
            icon = new ImageIcon("Australia.png");
            JOptionPane.showMessageDialog(null,
                                          "Ok Done",
                                          "Country Confirmation",
                                          JOptionPane.INFORMATION_MESSAGE,
                                          icon);
        }
    }     
}

Leave a Comment