如何运行JOptionPane对象

时间:2016-11-06 23:23:47

标签: java joptionpane

我有这个代码来运行JOptionPane对象

import import javax.swing.JOptionPane;
public class TheComboBoxes {
public static void main(String[] args) {
    JOptionPane optionPane = new JOptionPane(
            "The only way to close this dialog is by\n"
            + "pressing one of the following buttons.\n"
            + "Do you understand?",
            JOptionPane.QUESTION_MESSAGE,
            JOptionPane.YES_NO_OPTION);
    optionPane.createDialog("click");
}
}

然而,当我运行createDialog方法时没有任何反应,如何正确运行JOptionPane对象?

1 个答案:

答案 0 :(得分:0)

import javax.swing.JDialog;
import javax.swing.JOptionPane;
public class TheComboBoxes {
    public static void main(String[] args) {
        JOptionPane optionPane = new JOptionPane("The only way to close this dialog is by\n"
                + "pressing one of the following buttons.\n" + "Do you understand?", JOptionPane.QUESTION_MESSAGE,
                JOptionPane.YES_NO_OPTION);
        JDialog dialog = optionPane.createDialog("click");
        dialog.setVisible(true);
    }
}

使用JDialog显示您的窗口