Simple Ranking Application with JOptionPane showOptionDialog

Program

 

 

 

Program Source

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

public class Javaapp {

    public static void main(String[] args) {
        
        int var1=0,var2=0,var3=0; 
        ImageIcon icon = new ImageIcon("WLive48x48.png");
        String players[]={"Sachin Tendulkar","Sehwag","Dhoni"};
        while(true)
        {
            int optionReturns = JOptionPane.showOptionDialog(null
                                                     ,"Who is the best Indian cricket player?"
                                                     ,"Player Ranking"
                                                     ,JOptionPane.NO_OPTION
                                                     ,JOptionPane.PLAIN_MESSAGE
                                                     ,icon
                                                     ,players
                                                     ,"Sachin Tendulkar");
        if(optionReturns == 0)
            var1++;
        else if(optionReturns == 1)
            var2++;
        else if(optionReturns == 2)
            var3++;
        else if(optionReturns == -1)
        {
            JOptionPane.showMessageDialog(null,"Sachin Tendulkar = "+var1
                                            +"nSehwag = "+var2
                                            +"nDhoni  = "+var3);
            break;
        }
    }     
}

Leave a Comment