import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.io.*;
public class Note extends Frame {
private MenuBar mb;
private Menu mset_param ,mhelp;
private MenuItem mibc ,miSound;
private MenuItem miabout;
//缺省的背景颜色
private static Color backgroundcolor = Color.GRAY;
//funtction of the button on plcb is chose year andmonth
//and set alarm colock and remind booking
private JCheckBox remindBook ,alarmColock;
private JComboBox cbyears ,cbmonths;
private JPanel plcb;
//日历按钮
private JPanel plbt;
private JButton button[];
//add vector to contain button[],so that find it
private Vector v;
//save the year and month
private String choseyear ,chosemonth;
private int choseyearint ,chosemonthint;
private boolean changed = false;
private boolean fileExist = false;//the application first run to find file
private static boolean needSound;
//add text to write down what to do in the future
private TextArea tanote;
private JPanel plta;
//默认的年份
private final static String years[]={
“1995” ,”1996″ ,”1997″ ,”1998″ ,”1999″ ,”2000″ ,
“2001” ,”2002″ ,”2003″ ,”2004″ ,”2005″ ,”2006″ ,
“2007” ,”2008″ ,”2009″ ,”2010″ ,”2011″ ,”2012″ ,
“2013” ,”2014″ ,”2015″ ,”2016″ ,”2017″ ,”2018″ ,
“2019” ,”2020″
};
private static final String months[] = {
“January” ,”February” ,”March” ,”April” ,”May” ,”June” ,”July” ,”August” ,
“September” ,”October” ,”November” ,”December”
};
private final static int dom[] = {
31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31
};
//save the first day of the month to use
private int start;
//save the button who is entered
private int btnIndex;
public Note() {
mb = new MenuBar();
mset_param = new Menu(“设置”);
mhelp = new Menu(“帮助”);
mibc = new MenuItem(“背景”);
miSound = new MenuItem(“声音”);
miabout = new MenuItem(“关于…”);
mset_param.add(mibc);
mset_param.addSeparator();
mset_param.add(miSound);
mhelp.add(miabout);
setMenuBar(mb);
mb.add(mset_param);
mb.setHelpMenu(mhelp);
MListener ml = new MListener();
mibc.addActionListener(ml);
miabout.addActionListener(ml);
miSound.addActionListener(ml);
cbyears = new JComboBox();
cbmonths = new JComboBox();
plcb = new JPanel();
plcb.setLayout(new FlowLayout());
JLabel lyears = new JLabel(“年份:”);
JLabel lmonths = new JLabel(“月份:”);
plcb.add(lyears);
plcb.add(cbyears);
plcb.add(lmonths);
plcb.add(cbmonths);
remindBook = new JCheckBox(“预约提示”,true);
alarmColock = new JCheckBox(“闹钟”);
// Dimension d = new Dimension();
// remindBook.setSize(d);
// remindBook.getSize(d);
// System.out.println(“W:”+d.getWidth()+” H:”+d.getHeight());
plcb.add(remindBook);
plcb.add(alarmColock);
remindBook.addActionListener(new RemindListener());
alarmColock.addActionListener(new RemindListener());
add(plcb ,BorderLayout.NORTH);
//add calendar
getCalendar();
plbt = new JPanel();
plbt.setBackground(Color.BLUE);
plbt.setLayout(new GridLayout(7 ,7));
plbt.add(new JLabel(” 星期日”));
plbt.add(new JLabel(” 星期一”));
plbt.add(new JLabel(” 星期二”));
plbt.add(new JLabel(” 星期三”));
plbt.add(new JLabel(” 星期四”));
plbt.add(new JLabel(” 星期五”));
plbt.add(new JLabel(” 星期六”));
//add calendar button to frame
//add button to vector;
v = new Vector();
button = new JButton[42];
for(int i=0;i<41;i++){
button[i] = new JButton();
plbt.add(button[i]);
button[i].addActionListener(new ButtonListener());
v.add(button[i]);
}
button[41] = new JButton();
plbt.add(button[41]);
button[41].setText(“保存”);
button[41].addActionListener(new SaveListener());
add(plbt ,BorderLayout.CENTER);
//add note book
// plta = new JPanel();
tanote = new TextArea(5 ,80);
// tanote.addTextListener(new tanoteTextListener());
// tanote.setColumns(80);
// plta.add(tanote);
// tanote.SCROLLBARS_VERTICAL_ONLY;
add(tanote ,BorderLayout.SOUTH);
/*
//add date to button
GregorianCalendar calendar = new GregorianCalendar(choseyearint ,chosemonthint ,1);
int start = calendar.get(Calendar.DAY_OF_WEEK)-1;
int daysInMonth = dom[chosemonthint];
if(calendar.isLeapYear(choseyearint)&&chosemonthint == 1){
++daysInMonth;
}
for(int i =0;i button[start+i].setText(” “+(i+1)+” “); } */ //add the default year and month to JComboBox for(int i= 0;i<=25;i++){ cbyears.addItem(years[i]); } for(int i=0;i<12;i++){ cbmonths.addItem(months[i]); } /* //add current year and month cbyears.setSelectedIndex(choseyearint-1995); cbmonths.setSelectedIndex(chosemonthint); */ //show date to calendar showDate(); //open file add to note Calendar now = new GregorianCalendar(); int num = start + now.get(Calendar.DAY_OF_MONTH)-1; btnIndex = num; readFile(num); fileSound(); //add threadcb to listen jcombobox state new ThreadCB().start(); //listen the JComboBox of years and months cbyears.addItemListener(new cbyearsItemListener()); cbmonths.addItemListener(new cbmonthsItemListener()); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { dispose(); System.exit(0); } }); } /** *add menu listener to know the menu what do want to do */ class MListener implements ActionListener{ public void actionPerformed(ActionEvent e){ MenuItem i = (MenuItem)e.getSource(); if(i.equals(miabout)){ JOptionPane.showMessageDialog(null ,”日历记事本程序V1.0″,”关于…” ,JOptionPane.INFORMATION_MESSAGE); } else if(i.equals(mibc)){ //backgroundcolor = Color.BLACK; backgroundcolor = JColorChooser.showDialog(null ,”选择颜色…” ,getBackground()); setBackground(backgroundcolor); plbt.setBackground(backgroundcolor); // System.out.println(choseyear); //// } else{ JOptionPane.showMessageDialog(null ,”I am sorry ,this function is not complation” ,”Sorry” ,JOptionPane.INFORMATION_MESSAGE); } } } /** *add the year JComboBox listener to know what active */ class cbyearsItemListener implements ItemListener{ public void itemStateChanged(ItemEvent e){ // System.out.println(e.paramString()); // System.out.println(e.getStateChange()); // System.out.println(e.getItem().toString()); // if(e.getSource().equals(“1997”)){ // System.out.println(“1997 is chosed”); // } // else{ // System.out.println(“the System is not chose 1997”); // } // choseyear = e.getItem().toString(); changed = true; // showDate(); // cbmonths.setSelectedIndex(5); } } /** *add the month JComboBox listener to know what active */ class cbmonthsItemListener implements ItemListener{ public void itemStateChanged(ItemEvent e){ // System.out.println(choseyear); // chosemonth = e.getItem().toString(); changed = true; // chosemonthint = Integer.parseInt(chosemonth); // System.out.println(chosemonthint); // showDate(); } } public static void main(String args[]) { System.out.println(“Starting Note…”); Note mainFrame = new Note(); mainFrame.setSize(600, 400); mainFrame.setTitle(“日历记事本”); mainFrame.setBackground(backgroundcolor); mainFrame.setVisible(true); for(int i=0;i<10;i++){ System.out.print(“