我的学生注册系统遇到了问题。我正在尝试通过从 a 中ArrayList
选择一个对象来从 a中删除它JComboBox
。
public class Course {
public List<Student> Students;
public List<Module> Modules;
public Course()
{
Students = new ArrayList<Student>();
Modules = new ArrayList<Module>();
}
public class Del_Student extends JFrame
{
private Course newCourse;
public Del_Student(Course aCourse)
{
newCourse = aCourse;
JButton btnDel = new JButton("Delete");
JButton btnCancel = new JButton("Cancel");
JComboBox studentsBox = new JComboBox();
studentsBox.setPreferredSize(new Dimension(185,25));
for(int i=0; i<newCourse.Students.size();i++ )
{
String p = newCourse.Students.get(i).getFirstName();
studentsBox.addItem(p);
}
btnDel.addActionListener
(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
newCourse.Students.remove(studentsBox.getSelectedItem());
}
}
);
我已经从对象中添加了一个字符串以显示在 上JComboBox
,所以我要做的是选择该项目(由学生姓名显示),然后删除所选项目。