答案 0 :(得分:1)
答案 1 :(得分:0)
看起来您正在尝试根据JComboBox中的选定项设置变量。要做到这一点,你的语法是错误的,你不需要使用return关键字,只需设置你想要的变量。
如果需要返回值,则只返回要返回的值并更改方法签名以指定返回类型。
最后,不使用一组凌乱的if / else语句而是使用Map。它将更清晰,更有效,更容易在以后更改。此外,您的代码是否被选中为空。
答案 2 :(得分:0)
因此,当用户在studentComboBox
中选择其他值时,您希望jlabel1
更改其文字吗?如果是这样,应该这样做:
String h = getParameter("student1");
String i = getParameter("student2");
String j = getParameter("student3");
private void studentComboBoxItemStateChanged(java.awt.event.ItemEvent evt) {
if (studentComboBox.getSelectedItem().equals("Student 1")){
jlabel1.setText(h);
} else if (studentComboBox.getSelectedItem().equals("Student 2")){
jlabel1.setText(i);
} else if (studentComboBox.getSelectedItem().equals("Student 3")){
jlabel1.setText(j);
}
}
请注意studentComboBoxItemStateChanged
不需要返回任何内容。您只需在jlabel1
对象本身上调用方法。