这是一个java日历记事本的程序,有错,请大家帮我完成,谢啦!

hbf65432 2009-11-26 11:54:45
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();
}
}

}
...全文
434 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
tsc_spring 2011-07-01
  • 打赏
  • 举报
回复
我现在也正在弄这个
qqpipi000 2010-11-03
  • 打赏
  • 举报
回复
不是注册了啊,奇怪
qqpipi000 2010-11-03
  • 打赏
  • 举报
回复
你没帮按钮添加注册
JavaAlpha 2009-11-26
  • 打赏
  • 举报
回复
你的出现了什么错误?

把错误贴出来看看
JavaAlpha 2009-11-26
  • 打赏
  • 举报
回复
http://blog.csdn.net/JavaAlpha/archive/2009/05/08/4161752.aspx
我也写过一个记事本,你可以去看看。
hbf65432 2009-11-26
  • 打赏
  • 举报
回复
就是保存设置和删除设置这两个按钮不管用,你把这两个程序运行一下就知道了。

51,410

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧