这是一个java日历记事本的程序,有错,请大家帮我完成,谢啦!
package a;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class NotePad extends JPanel implements ActionListener {
Rili Rili;
File file;
JButton baocun, shanchu;
JPanel cpanel, toppanel;
Box dpanel;
JTextArea area;
JLabel label=new JLabel();
//日期字段
int year,month,day;
public NotePad(Rili rili) {
this.Rili=Rili;
file=rili.getFile();
this.setLayout(new BorderLayout());
toppanel = new JPanel();
toppanel.add(label);
cpanel = new JPanel();
area = new JTextArea(10, 20);
area.setLineWrap(true);
cpanel.add(area);
baocun = new JButton("保存日志");
baocun.addActionListener(this);
shanchu = new JButton("删除日志");
shanchu.addActionListener(this);
dpanel = new Box(BoxLayout.X_AXIS);
dpanel.setAlignmentX(CENTER_ALIGNMENT);
dpanel.add(baocun);
dpanel.add(shanchu);
this.add(toppanel,BorderLayout.NORTH);
this.add(cpanel,BorderLayout.CENTER);
this.add(dpanel, BorderLayout.SOUTH);
}
public void top(int year,int month,int day){
this.year=year;
this.month=month;
this.day=day;
label.setText(""+year+"年"+month+"月"+day+"日");
duqu(year,month,day);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==baocun){
baocun(year,month,day);
}
if(e.getSource()==shanchu){
shanchu(year,month,day);
}
}
public void duqu(int year,int month,int day){
try {
ObjectInputStream in=new ObjectInputStream(new FileInputStream(file));
Hashtable table=(Hashtable)in.readObject();
String txt=(String)table.get(""+year+month+day);
if(txt==null){
area.setText("没有记录");
}else{
area.setText(txt);
}
}catch (IOException e) {
}catch (ClassNotFoundException e) {
}
}
public void baocun(int year,int month,int day){
String txt=area.getText();
ObjectInputStream in;
Hashtable table;
try {
in = new ObjectInputStream(new FileInputStream(file));
table=(Hashtable)in.readObject();
String key=""+year+month+day;
table.put(key,txt);
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(table);
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public void shanchu(int year,int month,int day){
Hashtable table;
ObjectInputStream in;
try {
in = new ObjectInputStream(new FileInputStream(file));
table=(Hashtable)in.readObject();
String key=""+year+month+day;
table.remove(key);
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(file));
out.writeObject(table);
out.close();
area.setText("");
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
}