i need to how to give codings to buttons that are present in confirm dialog box. For Example if there are two buttons as "YES" and "NO" and if i click "YES" then the program should close. If i click no then th dialog box should return to the program. Given below are the codes that i have done up to now and i dont have any idea to proceed further. Please help.

class cancelListener implements ActionListener
{
       public void actionPerformed(ActionEvent ev)
       { 
                int n = JOptionPane.showConfirmDialog( frame,
                                        "Are You sure you want to Close?",
                                        "Confirm Log Off",
                                         JOptionPane.YES_NO_OPTION);
        }
}

You need to evaluate return value from JOptionPane stored in "n" and compare to possible outcomes so in your case only YES.

int n = JOptionPane.showConfirmDialog( frame,
    "Are You sure you want to Close?",
    "Confirm Log Off",
    JOptionPane.YES_NO_OPTION);
if(n == JOptionPane.YES_OPTION){
//CLOSE APPLICATION ACTION HERE
}

i need to how to give codings to buttons that are present in confirm dialog box. For Example if there are two buttons as "YES" and "NO" and if i click "YES" then the program should close. If i click no then th dialog box should return to the program. Given below are the codes that i have done up to now and i dont have any idea to proceed further. Please help.

class cancelListener implements ActionListener
{
       public void actionPerformed(ActionEvent ev)
       { 
                int n = JOptionPane.showConfirmDialog( frame,
                                        "Are You sure you want to Close?",
                                        "Confirm Log Off",
                                         JOptionPane.YES_NO_OPTION);
        }
}

thanx a lot bro!!! it really works.

You need to evaluate return value from JOptionPane stored in "n" and compare to possible outcomes so in your case only YES.

int n = JOptionPane.showConfirmDialog( frame,
    "Are You sure you want to Close?",
    "Confirm Log Off",
    JOptionPane.YES_NO_OPTION);
if(n == JOptionPane.YES_OPTION){
//CLOSE APPLICATION ACTION HERE
}

Thanx a lot bro!!!. It worked out and sorry for the mistake's, im new to JAVA as well as DANIWEB. thanx again for replying to my thread!!

Thanx a lot bro!!!. It worked out and sorry for the mistake's, im new to JAVA as well as DANIWEB. thanx again for replying to my thread!!

No need to apologies. 3 years back I was in similar position.

This question has already been answered. Start a new discussion instead.