我想知道使用控制器将本地学生(模型)拉到我的视图类中是否会使 MVC 设计模式无效。供参考我从来没有将我的学生模型导入到视图类中。控制器public void saveStudent(int selectedRow, Student studentChanged){ studentList.getStudentList().set(selectedRow, studentChanged);}看法Student currentStudent;. . . .public StudentDetailedUI(StudentCntrl studentCntrIn, int selectedRowIn) { studentCntrl = studentCntrIn; selectedRow = selectedRowIn; if (selectedRow >= 0) { currentStudent = studentCntrl.getStudent(selectedRow); initComponents(); parseCurrentStudent(); } else { initComponents(); parseNewStudent(); }}. . . .JButton saveButton = new JButton("Save"); saveButton.addActionListener((ActionEvent e) -> { if (selectedRow != -1){ currentStudent.setFirstName(firstNameDisplayValue.getText()); currentStudent.setLastName(lastNameDisplayValue.getText()); currentStudent.setUniversity(universityDisplayValue.getText()); currentStudent.setGpa(Double.parseDouble(gpaDisplayValue.getText())); StudentDetailedUI.this.studentCntrl.saveStudent(selectedRow, currentStudent); StudentDetailedUI.this.studentCntrl.getStudentListUI(); } else { StudentDetailedUI.this.studentCntrl.addStudent(firstNameDisplayValue.getText() +", " +lastNameDisplayValue.getText() +", " +universityDisplayValue.getText() +", " +gpaDisplayValue.getText()); StudentDetailedUI.this.studentCntrl.getStudentListUI(); } });我的预期功能是使用列表详细信息 GUI 更新列表中的现有学生。
添加回答
举报
0/150
提交
取消