javax选项中的JOptionPane

javax选项中的JOptionPane,java,swing,joptionpane,Java,Swing,Joptionpane,我需要Java中JOptionPane的帮助。单击“确定”时,一切正常。:)但是当我点击x时,它就像我点击OK一样。我怎样才能解决这个问题。当我点击x时,我想关闭应用程序。这是我的密码 import javax.swing.JList; import javax.swing.JOptionPane; public class Main { @SuppressWarnings("unchecked") public static void main(String[] args)

我需要Java中JOptionPane的帮助。单击“确定”时,一切正常。:)但是当我点击x时,它就像我点击OK一样。我怎样才能解决这个问题。当我点击x时,我想关闭应用程序。这是我的密码

import javax.swing.JList;
import javax.swing.JOptionPane;

public class Main {
    @SuppressWarnings("unchecked")
    public static void main(String[] args) {

        @SuppressWarnings("rawtypes")
        JList choise = new JList(new String[] { "Enter the complaints",
                "View complaints" });
        JOptionPane.showMessageDialog(null, choise, "Multi-Select Example",
                JOptionPane.PLAIN_MESSAGE);
        if (choise.getSelectedIndex() == 0) {
            new ComplaintsApp();
        } else if(choise.getSelectedIndex() == 1 && JOptionPane.OK_OPTION > 0){

            new ComplaintsView();
        }
    }
}

使用另一个JOptionPane,它会向程序返回按下哪个按钮的指示:
JOptionPane.showConfirmDialog(…)

import javax.swing.JList;
导入javax.swing.JOptionPane;
导入javax.swing.JScrollPane;
公共班机{
公共静态void main(字符串[]args){
JList choice=new JList(新字符串[]){
“输入投诉”、“查看投诉”});
int result=JOptionPane.showConfirmDialog(null,
新的JScrollPane(选项),“多选示例”,
JOptionPane.OK_取消_选项,JOptionPane.PLAIN_消息);
if(结果!=JOptionPane.OK\u选项){
//他们没有按OK
返回;
}
if(choice.getSelectedIndex()==0){
System.out.println(“投诉应用程序”);
}else if(choice.getSelectedIndex()==1){
System.out.println(“投诉视图”);
}
}
}
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;

public class Main {
    public static void main(String[] args) {

        JList<String> choice = new JList<>(new String[] {
                "Enter the complaints", "View complaints" });
        int result = JOptionPane.showConfirmDialog(null,
                new JScrollPane(choice), "Multi-select Example",
                JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
        if (result != JOptionPane.OK_OPTION) {
            // they didn't press OK
            return;
        }
        if (choice.getSelectedIndex() == 0) {
            System.out.println("Complaints App");
        } else if (choice.getSelectedIndex() == 1) {
            System.out.println("Complaints View");
        }
    }
}