有人可以告诉我我做错了什么吗?
我有..
JComboBox comboBox = new JComboBox();
comboBox.addItem("Factor 1");
comboBox.addItem("Factor 2");
comboBox.addItem("Factor 3");
comboBox.setSelectedIndex(-1);
studyPlanController.setFactors(comboBox);
MyItemListener itemListener = new MyItemListener();
comboBox.addItemListener(itemListener);
itemListener.setFactors(cardFactors);
和..
import java.awt.CardLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JPanel;
public class MyItemListener implements ItemListener {
JPanel factors;
public void setFactors(JPanel factors) {
this.factors = factors;
}
@Override
public void itemStateChanged(ItemEvent e) {
CardLayout cl = (CardLayout) (factors.getLayout());
cl.show(factors, (String) e.getItem());
}
}
当断点被放置在 itemStateChanged() 中,并且组合框被改变时,断点被命中,但是卡片布局仍然不受影响。