上面的JOptionPane就不可以用回车关掉, 因为JOptionPane没有默认值 ,
下面的就设置了默认值 ,所以可以用回车关掉JoptionPane
Object[] options = {"Yes, please",
"No way!"};
int n = JOptionPane.showOptionDialog(frame,
"Would you like green eggs and ham?",
"A Silly Question",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null, //do not use a custom Icon
options, //the titles of buttons
options[0]); //default button title
Object[] options = {"Yes, please", "No way!"};
JOptionPane.showOptionDialog(this,"Would you like green eggs and ham?", "A Silly Question", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, null);
最后一个null就是设置JOptionPane的默认值的参数