java x 选项中的 JOptionPane

JOptionPane in java x option

我在 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,returns 程序指示按下哪个按钮:JOptionPane.showConfirmDialog(...):

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");
        }
    }
}