JComboBox监听为什么不更新?
部分代码如下:
String User="User1";
name=new JComboBox();
choice.add("User1");
choice.add("User2");
choice.add("User3");
choice.add("User4");
name.add(choice);
name.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
if(e.getSource()==name){
User=name.getSelectedItem().toString();
}
}
}
);
我想要User随选择而更新,但是运行后发现User一直是"User1"