-1

我从 oracle 网站得到了这个下拉框的例子:

Object[] possibilities = {"ham", "spam", "yam"};
String s = (String)JOptionPane.showInputDialog(
                frame,
                "Complete the sentence:\n"
                + "\"Green eggs and...\"",
                "Customized Dialog",
                JOptionPane.PLAIN_MESSAGE,
                icon,
                possibilities,
                "ham");

//If a string was returned, say so.
if ((s != null) && (s.length() > 0)) {
setLabel("Green eggs and... " + s + "!");
return;
}

//If you're here, the return value was null/empty.
setLabel("Come on, finish the sentence!");

我只是想知道你如何改变每个选择的作用?例如,我是否需要更改语句中的某些内容if ((s != null) && (s.length() > 0)) {以便可以编辑第一个字符串项?

4

1 回答 1

0

好吧,检查用户选择了哪个项目并做某事非常简单

if ((s != null) && (s.length() > 0)) {

     if(s.equals(possibilities[0]);
         //HAM is chosen do something
     else if(s.equals(possibilities[1]);
         //spam and so on..........
     return;
}
于 2013-03-20T11:49:38.233 回答