题目二:GUI界面编程
额,怎么说呢,题目二涉及到GUI的东西异常的少,,只要求补全两个class的代码,其余的能看懂就可以做题
DisplayExamPaperListener
这个class几乎用不到,,,,
public void actionPerformed(ActionEvent event) {
if(studentCatalog.getNumberOfStudents ()==0){
statusTextArea.setText ("The catalog of students is empty.");
}else{
statusTextArea.setText(studentsFormatter.formatStudents(studentCatalog));
}
}
class SaveExamPaperListener
JFileChooser jFileChooser = new JFileChooser();
BufferedWriter bw=null;
if (0 == jFileChooser.showSaveDialog(null)) {
File saveFile = jFileChooser.getSelectedFile();
try {
if (!saveFile.exists()) {
saveFile.createNewFile();
}
bw = new BufferedWriter(new FileWriter(saveFile));
bw.write(studentsFormatter.formatStudents(studentCatalog));
}
catch (IOException e) {
e.printStackTrace();
}finally {
try {
bw.close ();
} catch (IOException e) {
e.printStackTrace ();
}
}
}
注意!!!
当补全以上两个class的内容时,代码并不能正常运行,尤其是当展示试卷的时候,因为我在之前Plain,
、XML和HTML单例模式输出studentcatalog时,没有考虑未生成试卷的情况,而这次的题目会出现有些student的exmepaper未生成的情况,因此记得加上判断条件,不然会报错。