用Java实现日历记事本 联系客服

发布时间 : 星期一 文章用Java实现日历记事本更新完毕开始阅读

public void setMonth(int month) { this.month=month; } public int getMonth() { return month; } public void setDay(int day) { this.day=day; } public int getDay() { return day; } public void setNews(int year,int month,int day) { News.setText(\年\月\日\ } public void setText(String s) { text.setText(s); } public void actionPerformed(ActionEvent e) {} public void Save(File file,int year,int month,int day) { //保存日志按钮事件实现 String LogCenter=text.getText(); 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) { try { FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); 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){} String f=\日志已更新\ JOptionPane.showMessageDialog(this,f,\提示\ } } else { String m=\年\月\还没有日志,是否保存日志?\//保存还没有的日志 int ok=JOptionPane.showConfirmDialog(this,m,\询问\ JOptionPane.QUESTION_MESSAGE); 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,LogCenter); FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); } catch(Exception ee){} String f=\日志保存成功\ JOptionPane.showMessageDialog(this,f,\提示\ } } } public void Delete(File file,int year,int month,int day) { //删除日志按钮事件实现 String key=\ if(table.containsKey(key)) { String m=\删除\年\月\日的日志吗?\ int yes=JOptionPane.showConfirmDialog(this,m,\询问\ JOptionPane.QUESTION_MESSAGE); if(yes==JOptionPane.YES_OPTION) { try { FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); 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){} String f=\日志删除成功\ JOptionPane.showMessageDialog(this,f,\提示\ } } else { String f=\年\月\无记录\ JOptionPane.showMessageDialog(this,f,\提示\ } } public void Read(File file,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,\询问\ if(ok==JOptionPane.YES_OPTION) { text.setText((String)table.get(key)); text.setText(\年\月\日的日志\ } else { text.setText(\ } } else { String f=\年\月\日,暂无记录\ JOptionPane.showMessageDialog(this,f,\提示\ } } } Year类 //Year.java 其源代码为: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Year extends Box implements ActionListener { int year; JTextField showYear=null; JButton Year1,Year2; CalendarPad CAL; public Year(CalendarPad CAL) {