/*
* 程序名称: 个人助理之日历记事薄
* 系统版本: Windows XP Professional sp3 100427-1650
* JRE版本: J2SE build 1.6.0_20-b02
* IDE版本: Eclipse Helios Release 20100617-1415
*/
import java.util.Calendar;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.Hashtable;
/**
* @Version 2010.9.13
* @author 07级计科4班 20074042173号 钟斯
* @Date 2010/09/13
*/
public class CalendarPad extends JFrame implements MouseListener {
/**
* CalendarPad类负责主面板
*/
private static final long serialVersionUID = 1L;
int year, month, day;
Hashtable<?, ?> hashtable = new Hashtable<Object, Object>();
File file;
JTextField showDay[];
JLabel title[];
Calendar ical;
int weekx;
NotePad notepad = null;
Month monthx;
Year yearx;
String strweek[] = { "星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六" };
JPanel leftPanel, rightPanel;
public CalendarPad(int year, int month, int day) {
leftPanel = new JPanel();
JPanel leftCenter = new JPanel();
JPanel leftNorth = new JPanel();
leftCenter.setLayout(new GridLayout(7, 7));
rightPanel = new JPanel();
this.year = year;
this.month = month;
this.day = day;
yearx = new Year(this);
yearx.setYear(year);
monthx = new Month(this);
monthx.setMonth(month);
title = new JLabel[7];
showDay = new JTextField[42];
for (int j = 0; j < 7; j++) {
title[j] = new JLabel();
title[j].setText(strweek[j]);
title[j].setBorder(BorderFactory.createRaisedBevelBorder());
leftCenter.add(title[j]);
}
title[0].setForeground(Color.red);
title[6].setForeground(Color.blue);
for (int i = 0; i < 42; i++) {
showDay[i] = new JTextField();
showDay[i].addMouseListener(this);
showDay[i].setEditable(false);
leftCenter.add(showDay[i]);
}
ical = Calendar.getInstance();
Box box = Box.createHorizontalBox();
box.add(yearx);
box.add(monthx);
leftNorth.add(box);
leftPanel.setLayout(new BorderLayout());
leftPanel.add(leftNorth, BorderLayout.NORTH);
leftPanel.add(leftCenter, BorderLayout.CENTER);
leftPanel.add(new Label("请在年份输入框输入所查年份(负数表示公元前),并回车确定"),
BorderLayout.SOUTH);
leftPanel.validate();
Container con = getContentPane();
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
leftPanel, rightPanel);
con.add(split, BorderLayout.CENTER);
con.validate();
file = new File("rem.db");
if (!file.exists()) {
try {
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream objectOut = new ObjectOutputStream(out);
objectOut.writeObject(hashtable);
objectOut.close();
out.close();
} catch (IOException e) {
}
}
notepad = new NotePad(this);
rightPanel.add(notepad);
setCalToken(year, month);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
setVisible(true);
setBounds(100, 50, 524, 285);
validate();
}
public void setCalToken(int year, int month) {
ical.set(year, month - 1, 1);
weekx = ical.get(Calendar.DAY_OF_WEEK) - 1;
if (month == 1 || month == 2 || month == 3 || month == 5 || month == 7
|| month == 8 || month == 10 || month == 12) {
SeqCalNum(weekx, 31);
} else if (month == 4 || month == 6 || month == 9 || month == 11) {
SeqCalNum(weekx, 30);
} else if (month == 2) {
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
SeqCalNum(weekx, 29);
} else {
SeqCalNum(weekx, 28);
}
}
}
public void SeqCalNum(int weekx, int months_days_num) {
for (int i = weekx, n = 1; i < weekx + months_days_num; i++) {
showDay[i].setText("" + n);
if (n == day) {
showDay[i].setForeground(Color.green);
showDay[i].setFont(new Font("TimesRoman", Font.BOLD, 20));
} else {
showDay[i].setFont(new Font("TimesRoman", Font.BOLD, 12));
showDay[i].setForeground(Color.black);
}
if (i % 7 == 6) {
showDay[i].setForeground(Color.blue);
}
if (i % 7 == 0) {
showDay[i].setForeground(Color.red);
}
n++;
}
for (int i = 0; i < weekx; i++) {
showDay[i].setText("");
}
for (int i = weekx + months_days_num; i < 42; i++) {
showDay[i].setText("");
}
}
public int getYear() {
return year;
}
public void setYear(int y) {
year = y;
notepad.setYear(year);
}
public int getMonth() {
return month;
}
public void setMonth(int m) {
month = m;
notepad.setMonth(month);
}
public int getDay() {
return day;
}
public void setDay(int d) {
day = d;
notepad.setDay(day);
}
public Hashtable<?, ?> getHashtable() {
return hashtable;
}
public File getFile() {
return file;
}
public void mousePressed(MouseEvent e) {
JTextField source = (JTextField) e.getSource();
try {
day = Integer.parseInt(source.getText());
notepad.setDay(day);
notepad.setLabel(year, month, day);
notepad.setTxt(null);
notepad.getDiaryContent(year, month, day);
} catch (Exception ee) {
}
}
public void mouseClicked(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public static void main(String args[]) {
Calendar calendar = Calendar.getInstance();
int y = calendar.get(Calendar.YEAR);
int m = calendar.get(Calendar.MONTH) + 1;
int d = calendar.get(Calendar.DAY_OF_MONTH);
new CalendarPad(y, m, d);
}
}
rem-notepad.rar_记事本日历
版权申诉
124 浏览量
2022-09-20
20:45:43
上传
评论
收藏 17KB RAR 举报
寒泊
- 粉丝: 75
- 资源: 1万+