JOptionPane输入对话框

时间:2014-12-12 16:54:53

标签: java input

我正在尝试创建一个输入框,用于接收用户的响应。我注意到eclipse在icon参数(文本,答案)之后给了我2个额外的参数,而且我不确定它们应该包含在内。

String answer = JOptionPane.showInputDialog(null, "Give us a word starting with "+text[i]+":", "ABCTutor", 0, image, text, answer);

1 个答案:

答案 0 :(得分:1)

查看Java's documentation

selectionValues - an array of Objects that gives the possible selections
initialSelectionValue - the value used to initialize the input field

一个例子:

Object[] options = { "OK", "CANCEL" };
JOptionPane.showOptionDialog(
    null,
    "Click OK to continue", 
    "Warning",
    JOptionPane.DEFAULT_OPTION,
    JOptionPane.WARNING_MESSAGE,
    null,
    options,  // available options
    options[0]); // default option