当前位置:首页 > 用Java实现日历记事本源代码2660【新版】
保存日志.addActionListener(this); 删除日志.addActionListener(this); setLayout(new BorderLayout()); JPanel pSouth=new JPanel();
add(信息条,BorderLayout.NORTH); pSouth.add(保存日志); pSouth.add(删除日志);
add(pSouth,BorderLayout.SOUTH);
add(new JScrollPane(text),BorderLayout.CENTER); }
public void actionPerformed(ActionEvent e) {
if(e.getSource()==保存日志) {
保存日志(year,month,day); }
else if(e.getSource()==删除日志) {
删除日志(year,month,day); } }
public void setYear(int year) {
this.year=year; }
public int getYear() {
return year; }
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 设置信息条(int year,int month,int day) {
信息条.setText(\年\月\日\ }
public void 设置文本区(String s) {
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,\询\~ 16 / 25 ~
JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION) {
text.setText((String)table.get(key)); } else {
text.setText(\ } } else {
text.setText(\无记录\ } }
...
问
public void 保存日志(int year,int month,int day) {
String 日志内容=text.getText();
String key=\
String m=\年\月\保存日志吗?\
int ok=JOptionPane.showConfirmDialog(this,m,\询问\ JOptionPane.QUESTION_MESSAGE); if(ok==JOptionPane.YES_OPTION) { try ~ 17 / 25 ~
{
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=\删除\年\月\日的日志吗?\~ 18 / 25 ~
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(); ~ 19 / 25 ~
out.close();
text.setText(null); }
catch(Exception ee) { } } } else {
String m=\年\月\无日志记录\ JOptionPane.showMessageDialog(this,m,\\ } } } 4、)Year 类
import javax.swing.*; import java.awt.*;
import java.awt.event.*;
public class Year extends Box implements ActionListener {
int year; JTextField showYear=null; JButton 明年,去年; CalendarPad 日历;
public Year(CalendarPad 日历) {
super(BoxLayout.X_AXIS); showYear=new JTextField(4);
showYear.setForeground(Color.blue);
showYear.setFont(new Font(\
...
提示
共分享92篇相关文档