我编写的代码创建了一个带有三个选项的JComboBox,并且在选择一个时应该打开一个新的JFrame,但没有任何反应。我哪里出错?
JComboBox comboBox = new JComboBox();
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
JComboBox comboBox = (JComboBox) arg0.getSource();
Object newItem = comboBox.getSelectedItem();
boolean same = newItem.equals(oldItem);
oldItem = newItem;
if (" Loan".equals(arg0.getActionCommand())){
Loan loan = new Loan();
loan.setVisible(true);
frame.setVisible(false);
}
else if (" Return".equals(arg0.getActionCommand())){
//Code to open new jframe.
}
else if (" Renew".equals(arg0.getActionCommand())){
//Code to open new jframe.
}
}
});