package calendar;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import java.awt.Font;
import java.applet.AudioClip;
import java.net.URL;
import java.applet.Applet;
class calendar extends JFrame{
JPanel panel = new JPanel(new BorderLayout());
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel(new GridLayout(7, 7));
JPanel panel3 = new JPanel();
JLabel[] label = new JLabel[49];
JLabel y_label = new JLabel("Year");
JLabel m_label = new JLabel("Month");
JComboBox com1 = new JComboBox();
JComboBox com2 = new JComboBox();
JButton button = new JButton("Find");
XYLayout xYLayout1 = new XYLayout();
JButton jButtonMemo = new JButton();
JButton jButtonAlert = new JButton();
JPanel jPanel1 = new JPanel();
XYLayout xYLayout2 = new XYLayout();
Calendar nowt = new GregorianCalendar();
String time;
int re_year, re_month;
int x_size, y_size;
String year_num;
Calendar now = Calendar.getInstance(); //设定Calendar
JPanel jPanel2_time = new JPanel();
JTextField jTextField1 = new JTextField();
XYLayout xYLayout3 = new XYLayout();
FlowLayout flowLayout1 = new FlowLayout();
JEditorPane jEditorPane1_Memo = new JEditorPane();
JEditorPane jEditorPane1_Alert = new JEditorPane();
calendar() {
super("Calendar");
setSize(400, 500);
x_size = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth());
y_size = (int) (Toolkit.getDefaultToolkit().getScreenSize().getHeight());
setLocation((x_size - 300) / 2, (y_size - 350) / 2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel1.add(y_label);
panel1.add(com1);
panel1.add(m_label);
panel1.add(com2);
panel1.add(button);
for (int i = 0; i < 49; i++) {
label[i] = new JLabel("", JLabel.CENTER); //将显示的字符居中
panel2.add(label[i]);
}
/*panel3.add(new calendar(this)); */
panel.add(panel1, BorderLayout.NORTH);
panel.add(panel2, BorderLayout.CENTER);
panel.add(panel3, BorderLayout.SOUTH);
panel.setBackground(Color.white);
panel1.setBackground(Color.white);
panel2.setBackground(Color.white);
panel3.setBackground(Color.white);
jbInit();
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int c_year, c_month, c_week;
c_year = Integer.parseInt(com1.getSelectedItem().toString()); //得到当前所选年份
c_month = Integer.parseInt(com2.getSelectedItem().toString()) -
1; //得到当前月份,并减1,计算机中的月为0-11
c_week = use(c_year, c_month); //调用函数use,得到星期
Resetday(c_week, c_year, c_month); //调用函数Resetday
}
});
setContentPane(panel);
setVisible(true);
setResizable(false);
}
class clock extends Thread {
Font f = new Font("宋体", Font.BOLD, 16);
SimpleDateFormat SDF = new SimpleDateFormat("HH:mm:ss"); //格式化时间显示类型
public void run() {
while (true) {
try {
Thread.sleep(1000);
Calendar nowt;
nowt = Calendar.getInstance();
time = SDF.format(nowt.getTime()); //得到当前日期和时间
jTextField1.setText(time);
jTextField1.setFont(f);
} catch (InterruptedException e) {
System.out.println("异常");
}
}
}
}
public void jbInit() {
int year, month_num, first_day_num;
String log[] = {"Sun", "Mon", "Tue", "Wed", "Thur", "Fri", "Sat"};
for (int i = 0; i < 7; i++) {
label[i].setText(log[i]);
}
for (int i = 0; i < 49; i = i + 7) {
label[i].setForeground(Color.MAGENTA); //将星期日的日期设置为品红色
}
for (int i = 6; i < 49; i = i + 7) {
label[i].setForeground(Color.green); //将星期六的日期设置为绿色
}
for (int i = 1; i < 10000; i++) {
com1.addItem("" + i);
}
for (int i = 1; i < 13; i++) {
com2.addItem("" + i);
}
clock t = new clock();
t.start();
month_num = (int) (now.get(Calendar.MONTH)); //得到当前时间的月份
year = (int) (now.get(Calendar.YEAR)); //得到当前时间的年份
com1.setSelectedIndex(year - 1); //设置下拉列表显示为当前年
com2.setSelectedIndex(month_num); //设置下拉列表显示为当前月
first_day_num = use(year, month_num);
Resetday(first_day_num, year, month_num);
panel3.setLayout(xYLayout1);
jButtonMemo.setFont(new java.awt.Font("Monotype Corsiva",
Font.BOLD | Font.ITALIC, 18));
jButtonMemo.setText("New Memo");
jButtonMemo.addMouseListener(new calendar_jButtonMemo_mouseAdapter(this));
jButtonAlert.setFont(new java.awt.Font("Monotype Corsiva", Font.ITALIC,
20));
jButtonAlert.setForeground(Color.red);
jButtonAlert.setText("Alarm");
jButtonAlert.addMouseListener(new calendar_jButtonAlert_mouseAdapter(this));
xYLayout1.setWidth(401);
xYLayout1.setHeight(291);
panel.setFont(new java.awt.Font("Viner Hand ITC", Font.BOLD, 12));
panel1.setFont(new java.awt.Font("MS UI Gothic", Font.PLAIN, 12));
panel2.setFont(new java.awt.Font("Lucida Fax", Font.PLAIN, 12));
jPanel1.setLayout(xYLayout2);
jPanel2_time.setBackground(Color.pink);
jPanel2_time.setLayout(xYLayout3);
jTextField1.setBackground(UIManager.getColor("inactiveCaptionText"));
jTextField1.setFont(new java.awt.Font("宋体", Font.BOLD, 19));
jTextField1.setForeground(SystemColor.activeCaption);
jTextField1.setText("jTextField1");
this.getContentPane().setLayout(flowLayout1);
jEditorPane1_Memo.setBackground(SystemColor.inactiveCaptionText);
jEditorPane1_Memo.setFont(new java.awt.Font("华文细黑", Font.PLAIN, 16));
jEditorPane1_Memo.setForeground(SystemColor.desktop);
jEditorPane1_Memo.setText("Memo Here");
jEditorPane1_Alert.setBackground(new Color(34, 195, 103));
jEditorPane1_Alert.setFont(new java.awt.Font("Viner Hand ITC",
Font.PLAIN, 15));
jEditorPane1_Alert.setForeground(Color.red);
jEditorPane1_Alert.setText("To-do list");
jPanel2_time.add(jTextField1, new XYConstraints(36, 6, 101, 28));
panel3.add(jButtonAlert, new XYConstraints(299, 233, 90, 40));
panel3.add(jPanel2_time, new XYConstraints(146, 233, 150, 40));
panel3.add(jButtonMemo, new XYConstraints(4, 233, 141, 40));
panel3.add(jEditorPane1_Memo, new XYConstraints(5, 3, 258, 216));
panel3.add(jEditorPane1_Alert, new XYConstraints(267, 3, 122, 216));
}
public int use(int reyear, int remonth) {
int week_num;
now.set(reyear, remonth, 1); //设置时间为所要查询的年月的第一天
week_num = (int) (now.get(Calendar.DAY_OF_WEEK)); //得到第一天的星期
return week_num;
}
class alarm extends Thread {
String todo = JOptionPane.showInputDialog("To-do");
String alarmtime = JOptionPane.showInputDialog("Set the time");
SimpleDateFormat SDF = new SimpleDateFormat("HH:mm:ss");
public void run() {
while (true) {