text.setText(s); } public void 获取日志内容(int year,int month,int day) { String key=\ try { FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); } catch(Exception ee) {} if(table.containsKey(key))
{ String m=\年\月\这一天有日志记载,想看吗?\ int ok=JOptionPane.showConfirmDialog(this,m,\询问\
JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION) {
String str = JOptionPane.showInputDialog(null,\请输入密码\消息对话框\
long num = Integer.parseInt(str); if(num!=123456){ JOptionPane.showInputDialog(this,\密码不正确!\确认对话框\ } else if(num==123456){ int n =JOptionPane.showConfirmDialog(this,\确认正确吗?\确认对话框\ text.setText((String)table.get(key)); } } else
{ text.setText(\ } } else
{ text.setText(\无记录\ }
17
} public void 保存日志(int year,int month,int day) { String 日志内容=text.getText(); String key=\ String m=\年\月\保存日志吗?\ int ok=JOptionPane.showConfirmDialog(this,m,\询问
\ if(ok==JOptionPane.YES_OPTION) { try { FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.put(key,日志内容); FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); } catch(Exception ee) {} } } public void 删除日志(int year,int month,int day) { String key=\ if(table.containsKey(key)) { String m=\删除\年\月\日的日志吗?\ int ok=JOptionPane.showConfirmDialog(this,m,\询问
\ if(ok==JOptionPane.YES_OPTION) { try { FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne);
18
table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.remove(key); FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); text.setText(null); } catch(Exception ee) {} } } else { String m=\年\月\无日志记录\ JOptionPane.showMessageDialog(this,m,\提示\ } } }
19
4系统运行与测试
4.1程序主界面
图1 日历记事本系统主界面
4.2日志查看——无日志
图2 无日志界面
20
4.3建立日志
图3 保存日志
4.4日志查看——有日志
图3有日志
21