日历记事本
上传者: hejinhong访问hejinhong的空间
分类: Java编程
软件名称: 日历记事本
添加日期: 2008-06-10 23:33
关注度: 24672467246724672467
下载次数: 61
软件说明:

 import java.awt.*;
 import java.awt.event.*;
 import javax.swing.*;
 import javax.swing.event.*;
 import javax.swing.border.*;
 import java.util.Date;
 import java.util.*;
 import java.io.*;
 import java.io.IOException;  //引入所需要的包
 public class calendar extends JFrame
    implements ActionListener,MouseListener
 {
    int year,month,day;  //定义 年 月 日
    int yearafterquery,monthafterquery;    //定义连个自定义转入指定的年月
    int startday;             //开始的天数                       
    String SwitchMonth;        //转换的月
    String SwitchNLMonth;
    String key;                //保存的文件名
    String strtext="";           
   
    int changeyearmessage;          //按钮转换的年
    int changemonthmessage;        //按钮转换的月
   
    int priormonth;                //自己想查看的年
    int prioryear;                 //自己想查看的月
   
    boolean ischange=false;         //是否改变
    boolean ischange_priornext=false;  //是否改变当前
   
    private JPanel LeftPane,RightPane;  //定义左右两个面板
   
    //左
    private JLabel YearLabel;      //年标签
    private JLabel MonthLabel;     //月标签
    private JComboBox MonthCombobox;   //月的组合框                                          
    private JTextField ShowDays[]= new JTextField[42];  
    private JTextField YearText;       //单行年的文本框
    private JLabel Ask;       //提示输入的语句
    private JLabel ShowDate;   //显示日期标签
    private JLabel Blank;     
    private JLabel TopBarTitle[]=new JLabel[7]; //7个星期的标签
    private JLabel ToToday;   //按钮(转换到今天)
    private JButton Query;     //按钮(转换)
    private String week[]={"SUN","MON","TUE","WED","THU","FRI","SAT"}; //星期
   
    //右
    private JLabel NorthMonthDayYear;  //显示年月日的标签
    private JLabel NorthNLMonthDayYear;  //显示农历的标签
    private JTextArea CenterText;       //多行文本框
    private JButton SouthSave,SouthDelete;  //按扭 (保存,删除)
    private JButton PriorMonth;   //前一个月
    private JButton NextMonth;    //下一个月
   
    JPopupMenu pop=new JPopupMenu("弹出"); //定义右键弹出菜单
       
    JMenuItem pundo=new JMenuItem("撤销");
    JMenuItem pcut=new JMenuItem("剪切");
    JMenuItem pcopy=new JMenuItem("复制");
    JMenuItem ppaste=new JMenuItem("粘贴");
    JMenuItem pdelete=new JMenuItem("删除");
    JMenuItem pselectAll=new JMenuItem("全选");
      
   
    public static void main(String[] args) throws Exception  //主函数
    {
        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);   //获取系统的日
       
        calendar frame = new calendar(y,m,d);  //初始化calendar
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);   //关闭按扭时退出程序
        frame.setSize(560,350);       //设置大小
        frame.setLocation(200,200);   //打开程序时窗口出现的位置
        frame.setVisible(true);       //设置可见
        frame.setResizable(false);   //设置窗口大小不能改变
        frame.ReadRecord();   //读取当天保存的日记
    }
   
    public calendar(int year,int month,int day)
    {
        setTitle("欢迎使用我忘了日历记事本");  //设置标签
       
      //添加文本框的右键的选项
        pundo.setActionCommand("pundo");
        pcut.setActionCommand("pcut");
        pcopy.setActionCommand("pcopy");
        ppaste.setActionCommand("ppaste");
        pdelete.setActionCommand("pdelete");
        pselectAll.setActionCommand("pselectAll");
       
        pundo.addActionListener(this);
        pcut.addActionListener(this);
        pcopy.addActionListener(this);
        ppaste.addActionListener(this);
        pdelete.addActionListener(this);
        pselectAll.addActionListener(this);
       
        pop.add(pundo);
        pop.addSeparator();
        pop.add(pcut);
        pop.add(pcopy);
        pop.add(ppaste);
        pop.add(pdelete);
        pop.addSeparator();
        pop.add(pselectAll);
       
        pcut.setEnabled( false );
        pcopy.setEnabled( false );
        pdelete.setEnabled( false );
       
      
       
        //左
        LeftPane = new JPanel();  //实例化
                //将左边的面板分成北和中两个小面板
        JPanel LeftCenter = new JPanel(); //初始化左 中
        JPanel LeftNorth = new JPanel();   //初始化左 北
        SwitchMonth(month);//把月份转换成相对应的英文
        LeftPane.setLayout(new BorderLayout());   //设置布局管理器 (默认)
        LeftPane.add(LeftNorth,BorderLayout.NORTH);   //添加左 北面板
        LeftPane.add(LeftCenter,BorderLayout.CENTER);  //添加左 中面板
        ToToday=new JLabel("                 您好,今天是 "+SwitchMonth+","+day+","+year);
        LeftPane.add(ToToday ,BorderLayout.SOUTH);//添加
        LeftPane.validate(); //确保组件具有有效的布局
       
        //设置布局 (左 北)
        LeftNorth.setLayout(new GridLayout(3,1,0,-2));  //设置网个布局
        LeftNorth.add(Ask = new JLabel(" 请输入你要查看的日期:")); //设置提示标签
        JPanel North = new JPanel(new FlowLayout(0,8,0));  //一个接一个放入容器  间距为8
        LeftNorth.add(North);               //添加到面板中去
        North.add(YearLabel=new JLabel("年:"));     //添加年的标签
        North.add(YearText = new JTextField(4));    //添加一个文本框
        YearText.setForeground(Color.darkGray);
        YearText.setFont(new Font("TimesRoman",Font.BOLD,17));//设置字体
        YearText.addActionListener(this); //兼听
        YearText.setFocusable(true);   //是指使YearText能够被聚焦 光标放置的位置
       
        North.add(Blank=new JLabel(" ")); //添加空白
        North.add(MonthLabel = new JLabel("月:")); //添加月
        North.add(MonthCombobox = new JComboBox());//添加月份的组合框
        //在组合框里添加月份
        for(int i=1;i<=12;i++)
        {
            MonthCombobox.addItem(new Integer(i));
        }
        //转换月份
        MonthCombobox.setForeground(Color.darkGray); //设置颜色
        MonthCombobox.setFont(new Font("TimesRoman",Font.BOLD,12));   //设置字体
        North.add(Blank=new JLabel(" "));     //添加空白
       
        North.add(Query=new JButton("转至"));
        Query.addActionListener(this);     //兼听
       
        JPanel North2=new JPanel(new FlowLayout());//定义下一个棉板
        LeftNorth.add(North2);          //添加到总面板里去
        North2.add(PriorMonth=new JButton("<<"));
        PriorMonth.addActionListener(this);
        PriorMonth.setActionCommand("prior");
        priormonth=month;
        prioryear=year;
       
       
        North2.add(ShowDate = new JLabel(SwitchMonth+" "+","+" "+String.valueOf(year),SwingConstants.CENTER));
        ShowDate.setFont(new Font("TimesRoman",Font.BOLD,14));
        North2.add(NextMonth=new JButton(">>"));
        NextMonth.addActionListener(this);
        NextMonth.setActionCommand("next");
       
       
       
        //左边中间面板
        LeftCenter.setLayout(new GridLayout(7,7));
        //输出标题
        for(int i=0;i<7;i++)
        {
            TopBarTitle[i]=new JLabel();
            TopBarTitle[i].setText(week[i]);  //设置文本
            TopBarTitle[i].setForeground(Color.darkGray);//前面字体颜色
            TopBarTitle[i].setHorizontalAlignment(0);   //对齐
            TopBarTitle[i].setBorder(BorderFactory.createRaisedBevelBorder()); //设置边界
            LeftCenter.add(TopBarTitle[i]);
        }
       
        //添加日期框
        for(int i=0;i<42;i++)
        {
            ShowDays[i]=new JTextField();
            ShowDays[i].addMouseListener(this); //鼠标兼听
            ShowDays[i].setEditable(false);//设置不可以编辑
            LeftCenter.add(ShowDays[i]);  // 添加这个
         }
        
         //输出月的部分
         PrintMonthBody(year,month,day);
        
        
        
        //右边布局
        RightPane = new JPanel(new BorderLayout());
        JPanel RightCenter = new JPanel();  //右中
        JPanel RightNorth = new JPanel(new BorderLayout());   //右 北
        JPanel RightSouth = new JPanel(new FlowLayout()); //右 南
        JPanel RightNorthNorth= new JPanel();
        JPanel RightCenterCenter= new JPanel();
        //添加面板
        RightPane.add(RightNorth,BorderLayout.NORTH);
        RightPane.add(RightCenter,BorderLayout.CENTER);
        RightPane.add(RightSouth,BorderLayout.SOUTH);
        RightNorth.add(RightNorthNorth,BorderLayout.NORTH);
        RightNorth.add(RightCenterCenter,BorderLayout.CENTER);

        RightNorthNorth.add(NorthMonthDayYear=new JLabel("你查看的日期的阳历为:"+SwitchMonth+","+day+","+year));//添加标签
        key=year+"_"+SwitchMonth+"_"+day;
       
        //设置显示农历
        int[] rNong = Change(year, month, day);
        SwitchNLMonth(rNong[1]);
        String NLmoth=SwitchNLMonth;
        if(rNong[2]<11)
        {
        SwitchNLMonth(rNong[2]);
        String NLday=SwitchNLMonth;
        RightCenterCenter.add(NorthNLMonthDayYear=new JLabel("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"初"+NLday));
        }
        else if(11<=rNong[2]&&rNong[2]<20)
          {
           SwitchNLMonth(rNong[2]-10);
           String NLday=SwitchNLMonth;
           RightCenterCenter.add(NorthNLMonthDayYear=new JLabel("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"十"+NLday));
           }
        else if(20<=rNong[2]&&rNong[2]<30)
           {
            SwitchNLMonth(rNong[2]-20);
            String NLday=SwitchNLMonth;
            RightCenterCenter.add(NorthNLMonthDayYear=new JLabel("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"二"+NLday));
           }
        else
           {
            SwitchNLMonth(rNong[2]-30);
            String NLday=SwitchNLMonth;
            RightCenterCenter.add(NorthNLMonthDayYear=new JLabel("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"三"+NLday));
           }
          
        NorthMonthDayYear.setForeground(Color.darkGray);//设置出现日期的颜色
        NorthMonthDayYear.setFont(new Font("TimesRoman",Font.BOLD,12)); //字体大小
        NorthNLMonthDayYear.setFont(new Font("TimesRoman",Font.BOLD,12));
        RightCenter.add(CenterText=new JTextArea("今天还没有写日记."));  //添加文本框
        CenterText.setLineWrap(true);        //是否自动换行
        CenterText.addFocusListener( new  Filechange());//注册 兼听鼠标显示右键
        CenterText.addMouseListener( new  MouseAdapter()
              {
                 public   void  mouseReleased(MouseEvent e)
                  {
                     if (e.isPopupTrigger())
                      {
                        pop.show(e.getComponent(),e.getX(),e.getY());
                      }
                }
            } );
           
        //添加删除和保存
        RightSouth.add(SouthSave=new JButton("        保存        "));
        SouthSave.addActionListener(this);
        SouthSave.setActionCommand("保存");
        RightSouth.add(SouthDelete=new JButton("      删除      "));
        SouthDelete.addActionListener(this);
        SouthDelete.setActionCommand("删除");
       
        //传递值
        this.year = year;
        this.month = month;
        this.day = day;
       
       
        //在容易器把左右面板都加进去
        Container container=getContentPane();  //返回引发事件的容器
        JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,LeftPane,RightPane); //分割两个面板
        container.add(split,BorderLayout.CENTER);
        container.validate();  //确保有效性
        setFont(new Font("Times New Roman",Font.PLAIN,12));
        JScrollPane scrollpane = new JScrollPane(CenterText);//设置可以滚动的窗格
        scrollpane.setPreferredSize(new Dimension(220,220)); //设置大小
        RightCenter.add(scrollpane);   //添加进去
       
    }
   
    //把月份转换成相对应的英文******************************************************
    public void SwitchMonth(int month)
    {
        switch(month)
        {
            case 1:
                SwitchMonth="Jan";break;
            case 2:
                SwitchMonth="Feb";break;
            case 3:
                SwitchMonth="Mar";break;
            case 4:
                SwitchMonth="Apr";break;
            case 5:
                SwitchMonth="May";break;
            case 6:
                SwitchMonth="Jun";break;
            case 7:
                SwitchMonth="Jul";break;
            case 8:
                SwitchMonth="Aug";break;
            case 9:
                SwitchMonth="Sep";break;
            case 10:
                SwitchMonth="Qct";break;
            case 11:
                SwitchMonth="Nov";break;
            case 12:
                SwitchMonth="Dec";break;
            }
       
    }
    /***********************************************************/
    //数字转换成中文 为了表示农历
    public void SwitchNLMonth(int month)
    {
     switch(month)
        {
            case 0:
                SwitchNLMonth="十";break;
            case 1:
                SwitchNLMonth="一";break;
            case 2:
                SwitchNLMonth="二";break;
            case 3:
                SwitchNLMonth="三";break;
            case 4:
                SwitchNLMonth="四";break;
            case 5:
                SwitchNLMonth="五";break;
            case 6:
                SwitchNLMonth="六";break;
            case 7:
                SwitchNLMonth="七";break;
            case 8:
                SwitchNLMonth="八";break;
            case 9:
                SwitchNLMonth="九";break;
            case 10:
                SwitchNLMonth="十";break;
            case 11:
                SwitchNLMonth="十一";break;
            case 12:
                SwitchNLMonth="十二";break;
         } 
   }
    /*********************************************************/
    //把每月天数排版显示出来
    public void PrintMonthBody(int year,int month,int day)
    {
       Calendar   currentCalendar=Calendar.getInstance();   //创建一个日历类  
       currentCalendar.set(year,month-1,1);  
       int   whatWeekBof=currentCalendar.get(Calendar.DAY_OF_WEEK)-1;  
       int   dataActualMaximum=currentCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        for(int   i=0;i<whatWeekBof;i++)  
             {  
           ShowDays[i].setText(""); 
            }
       for(int   i=whatWeekBof,n=1;i<(whatWeekBof+dataActualMaximum);i++)
       {
        ShowDays[i].setText(""+n);
        ShowDays[i].setHorizontalAlignment(0);//设置位置防在中间
        if(n==day)
            {
             ShowDays[i].setForeground(Color.red); //系统当天的天数颜色
             ShowDays[i].setFont(new Font("TimesRoman",Font.BOLD,18));
            }
            else
            {
             ShowDays[i].setFont(new Font("TimesRoman",Font.BOLD,12));
             ShowDays[i].setForeground(Color.DARK_GRAY);
            }
            n++;
       }
    }
   
  /*****************************************************************************/
    //保存记录 
    public void WriteRecord()
    {
        String content;
        content=CenterText.getText();  
        int n=content.length();
        char[] contentarr=new char[n];
        try
        {
            int i=0;
            for(i=0;i<n;i++)
            {
                contentarr[i]=content.charAt(i);
            }
            File Diary = new File("diary");   //用文件对象流建立对象
            Diary.mkdir(); //创建此抽象路径名指定的目录。
            File myfile=new File("Diary\\"+key+".txt");  //创建流
            FileWriter Record=new FileWriter(myfile);  //对指定的myfile创建FileWriter对象
            for(i=0;i<contentarr.length;i++)
            {
                Record.write(contentarr[i]);
            }
            Record.close();
            JOptionPane.showMessageDialog(this,"保存成功!"); //保存成功
        }
        catch(IOException e)
        {
        }
    }
 /****************************************************************************/
  //读取记录   
    public void ReadRecord()
    {
        try
        {
            String content="";  //初始化
            File myfile=new File("Diary\\"+key+".txt");
            FileReader Record=new FileReader(myfile);//创建读取对象
            if(myfile.exists())
            {
                long b=myfile.length();
                int n=JOptionPane.showConfirmDialog(this,"今天有日记你是否想查看?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);
                if(n==JOptionPane.YES_OPTION)
                {
                    while((b=Record.read())!=-1)
                    {
                        content=content+(char)b;
                    }
                    CenterText.setText(content);
                }
            }  
            Record.close();
        }
        catch(IOException e)
        {
            CenterText.setText("今天还没有写日记");
        }
    }
 /***************************************************************************/
 //删除
    public void DeleteFile()
    {
        String filepath="Diary\\"+key+".txt";
        File myfile=new File(filepath);

        int n=JOptionPane.showConfirmDialog(this,"你确定要删除文件吗 ?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION);
        if(n==JOptionPane.YES_OPTION)
        {
            if(myfile.exists())
            {
                Runtime rt = Runtime.getRuntime();//使应用程序能够与其运行的环境相连接
                try
                {
                    rt.exec("cmd /c del "+filepath);  //删除
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
                JOptionPane.showMessageDialog(this,"删除成功!");
               
                CenterText.setText("今天还没有写日记");
            }
            else
            {
                JOptionPane.showMessageDialog(this,"文件为空没有可以删除的!");
            }
        }
       
    }
 /******************************************************************************/
 //自己定义想查看的日期转化  
    public void AboutActionListenerWay()
    {
        try
        {
            prioryear=Integer.parseInt(YearText.getText());  //根据指定的基数radix返回字符串s表示的整数,如果省略了radix,则基数为10;
            priormonth=MonthCombobox.getSelectedIndex()+1;   //获得月份
            String StrYearText=YearText.getText();          
            changeyearmessage=Integer.parseInt(StrYearText);  
           
            changemonthmessage=MonthCombobox.getSelectedIndex()+1;
           
            monthafterquery=changemonthmessage;
            yearafterquery=changeyearmessage;
            SwitchMonth(changemonthmessage);  //转换成对应的英文
               
            ShowDate.setText(SwitchMonth+" "+","+" "+String.valueOf(changeyearmessage)); //改变显示
                   
            PrintMonthBody(changeyearmessage,changemonthmessage,day);  //转换月份和年
            ischange=true;  //是否转换
        }
        catch(Exception ee)
        {
            JOptionPane.showMessageDialog(this,"年份不能为空或输入不合法 请输重新入","Error",JOptionPane.ERROR_MESSAGE);
        }
    }
/******************************************************************************/
//显示改变后农历
   public void NLxianshi(int year1, int month1, int day1)
   {
   int[] rNong = Change(year1, month1, day1);
    SwitchNLMonth(rNong[1]);
    String NLmoth=SwitchNLMonth;
    if(rNong[2]<11)
    {
    SwitchNLMonth(rNong[2]);
    String NLday=SwitchNLMonth;
    NorthNLMonthDayYear.setText("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"初"+NLday);
    }
   else if(11<=rNong[2]&&rNong[2]<20)
    {
     SwitchNLMonth(rNong[2]-10);
     String NLday=SwitchNLMonth;
     NorthNLMonthDayYear.setText("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"十"+NLday);
    }
    else if(20<=rNong[2]&&rNong[2]<30)
    {
     SwitchNLMonth(rNong[2]-20);
      String NLday=SwitchNLMonth;
      NorthNLMonthDayYear.setText("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"二"+NLday);
     }
    else
   {
    SwitchNLMonth(rNong[2]-30);
    String NLday=SwitchNLMonth;
    NorthNLMonthDayYear.setText("阴历为: "+rNong[0]+"年"+NLmoth+"月"+"三"+NLday);
    }
   }
/**************************************************************************/   
 //事件兼听
    public void actionPerformed(ActionEvent eAction)
    {
        String ActionCommand=eAction.getActionCommand(); //获得标签
       
       
        if(eAction.getSource() instanceof JButton)
        {
           
            if("转至".equals(ActionCommand))
            {
                try
                {
                    AboutActionListenerWay();
                }
                catch(Exception ee)
                {
                    JOptionPane.showMessageDialog(this,"年份不能为空或输入不合法 请输重新入","Error",JOptionPane.ERROR_MESSAGE);
                }
            }
           
           
            if("prior".equals(ActionCommand))
            {
                    if(priormonth>1)
                    {
                        priormonth=priormonth-1;
                    }
                    else
                    {
                        priormonth=12;
                        prioryear=prioryear-1;
                    }
                    PrintMonthBody(prioryear,priormonth,day);
                    SwitchMonth(priormonth);
                    ShowDate.setText(SwitchMonth+" , "+prioryear);
                    NorthMonthDayYear.setText("你查看的日期的阳历为:"+SwitchMonth+","+day+","+prioryear);
                    key=prioryear+"_"+SwitchMonth+"_"+day;
                    NLxianshi(prioryear, priormonth, day);
                  
                    ischange_priornext=true;
            }
           
       
            if("next".equals(ActionCommand))
            {
                    if(priormonth<12)
                    {
                        priormonth=priormonth+1;
                    }
                    else
                    {
                        priormonth=1;
                        prioryear=prioryear+1;
                    }
                    PrintMonthBody(prioryear,priormonth,day);
                    SwitchMonth(priormonth);
                    ShowDate.setText(SwitchMonth+" , "+prioryear);
                    NorthMonthDayYear.setText("你查看的日期的阳历为:"+SwitchMonth+","+day+","+prioryear);
                    key=prioryear+"_"+SwitchMonth+"_"+day;
                    NLxianshi(prioryear, priormonth, day);
                   
                    ischange_priornext=true;
             }
       
           
            //保存
            if("保存".equals(ActionCommand))
            {
                WriteRecord();
            }
           
           
            if("删除".equals(ActionCommand))
            {
                DeleteFile();
            }
           
          }
       
        if ("pundo".equals(ActionCommand))  //是"撤消"操作触发
            {  
          CenterText.setText(strtext);
            }
           if (ActionCommand.equals("pcut"))   //是"剪切"操作触发
            {  strtext = CenterText.getText();
          CenterText.cut();
            }
          if ("pcopy".equals(ActionCommand))  //是"复制"操作触发
            {  strtext = CenterText.getText();
          CenterText.copy();
            }
          if ("ppaste".equals(ActionCommand))  ////是"粘贴"操作触发
            {  strtext = CenterText.getText();
          CenterText.paste();
            }
          if ("pdelete".equals(ActionCommand))  //是"删除"操作触发
            {
           strtext = CenterText.getText();  //保存文本内容
            CenterText.replaceSelection( "" );//用给定字符串所表示的新内容替换当前选定的内容
            }
          if ("pselectAll".equals(ActionCommand))  //是"删除"操作触发
            {
           strtext = CenterText.getText();  //保存文本内容
            CenterText.selectAll(  );//设置全选
            }
        //JTextField时间
        if(eAction.getSource() instanceof JTextField)
        {
            AboutActionListenerWay();
        }
      
    }
 /***********************************************************************************/
 //鼠标单击事件    
    public void mousePressed(MouseEvent eMouse)
    {
        int day;
       
        try
        {
            //兼听ShowDays[]时间
           
            if(ischange==false)
            {
 
                JTextField source=(JTextField)eMouse.getSource();
       
                day=Integer.parseInt(source.getText());  //转换
                if(ischange_priornext==false)
                {
                    NorthMonthDayYear.setText("你查看的日期的阳历为:"+SwitchMonth+","+day+","+year);
               
                    key=year+"_"+SwitchMonth+"_"+day;
                    NLxianshi(year, month, day);
                }
                else
                {
                    NorthMonthDayYear.setText("你查看的日期的阳历为:"+SwitchMonth+","+day+","+prioryear);
                     NLxianshi(prioryear, priormonth, day);
                   
                    key=prioryear+"_"+SwitchMonth+"_"+day;
                }
            }
            else
            {
                JTextField source=(JTextField)eMouse.getSource();
       
                day=Integer.parseInt(source.getText());
               
                if(ischange_priornext==false)
                {
                    SwitchMonth(changemonthmessage);
               
                    NorthMonthDayYear.setText("你查看的日期的阳历为:"+SwitchMonth+","+day+","+changeyearmessage);
           
                    key=changeyearmessage+"_"+SwitchMonth+"_"+day;
                    NLxianshi(changeyearmessage, changemonthmessage, day);
                   
                }
                else
                {
                    SwitchMonth(priormonth);
                   
                    NorthMonthDayYear.setText("你查看的日期的阳历为:"+SwitchMonth+","+day+","+prioryear);
           
                    key=prioryear+"_"+SwitchMonth+"_"+day;
                    NLxianshi(prioryear, priormonth, day);
                   
                }
            }

            ReadRecord();  //读取这天的记录
        }
        catch(Exception ee)
        {
        }
    }
   
   
    public void mouseClicked(MouseEvent e)
    {
    }
   
    public void mouseReleased(MouseEvent e)
    {
    }
   
    public void mouseEntered(MouseEvent e)
    {
    }
   
    public void mouseExited(MouseEvent e)
    {
    }
  /***********************************************************/
  //农历算法
    public int[] Change(int year, int month, int day) {
        int NongDate[] = new int[5];
        int nong[][] = {                   //农历1949年至2020年的农历
                { 7, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 1, 29, 29 },
                { 0, 29, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 2, 17, 0 },
                { 0, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 2, 6, 0 },
                { 5, 29, 30, 29, 30, 29, 29, 30, 30, 29, 30, 29, 30, 1, 27, 30 },
                { 0, 29, 30, 29, 29, 30, 30, 29, 30, 30, 29, 30, 29, 2, 14, 0 },
                { 0, 30, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 2, 3, 0 },
                { 3, 29, 30, 29, 29, 29, 30, 29, 30, 29, 30, 30, 30, 1, 24, 30 },
                { 0, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 2, 12, 0 },
                { 8, 30, 29, 30, 29, 30, 29, 29, 30, 30, 29, 30, 29, 1, 31, 29 },
                { 0, 30, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 2, 18, 0 },
                { 0, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 2, 8, 0 },
                { 6, 30, 29, 30, 29, 30, 30, 30, 29, 30, 29, 30, 29, 1, 28, 29 },
                { 0, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 2, 15, 0 },
                { 0, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 2, 5, 0 },
                { 4, 30, 29, 30, 29, 30, 29, 30, 29, 30, 30, 30, 29, 1, 25, 29 },
                { 0, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 2, 13, 0 },
                { 0, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 2, 2, 0 },
                { 3, 30, 30, 30, 30, 29, 29, 30, 29, 29, 30, 30, 29, 1, 21, 29 },
                { 0, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 30, 2, 9, 0 },
                { 7, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 1, 30, 30 },
                { 0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 2, 17, 0 },
                { 0, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 2, 6, 0 },
                { 5, 29, 30, 29, 29, 30, 30, 29, 30, 30, 30, 29, 30, 1, 27, 30 },
                { 0, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 2, 15, 0 },// 72年
                { 0, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 2, 3, 0 },
                { 4, 30, 30, 29, 30, 29, 30, 29, 29, 30, 30, 29, 30, 1, 23, 29 },// 74
                { 0, 30, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 2, 11, 0 },
                { 8, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 1, 31, 29 },
                { 0, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 29, 2, 18, 0 },
                { 0, 30, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 2, 7, 0 },
                { 6, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 1, 28, 30 },
                { 0, 30, 29, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 2, 16, 0 },
                { 0, 29, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 2, 5, 0 },
                { 4, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 30, 30, 1, 25, 29 },
                { 0, 30, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 2, 13, 0 },
                { 10, 30, 29, 30, 30, 29, 29, 30, 29, 29, 30, 30, 30, 2, 2, 29 },//84
                { 0, 29, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 2, 20, 0 },
                { 0, 29, 30, 30, 29, 30, 30, 29, 30, 29, 30, 29, 29, 2, 9, 0 },
                { 6, 30, 29, 30, 29, 30, 30, 30, 30, 29, 30, 29, 29, 1, 29, 29 },// 87
                { 0, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 2, 17, 0 },
                { 0, 30, 29, 29, 30, 29, 29, 30, 30, 29, 30, 30, 30, 2, 6, 0 },
                { 5, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 30, 30, 1, 27, 29 },
                { 0, 29, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 2, 15, 0 },
                { 0, 29, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 2, 4, 0 },
                { 3, 29, 30, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 1, 23, 29 },
                { 0, 30, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 2, 10, 0 },
                { 8, 29, 30, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 1, 31, 29 },
                { 0, 29, 30, 29, 30, 30, 29, 30, 29, 30, 30, 29, 29, 2, 19, 0 },
                { 0, 30, 29, 30, 29, 30, 29, 30, 30, 29, 30, 30, 29, 2, 7, 0 },// 97
                { 5, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 29, 30, 1, 28, 29 },
                { 0, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 2, 16, 0 },
                { 0, 30, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 2, 5, 0 },// 00
                { 4, 30, 30, 29, 30, 30, 29, 29, 30, 29, 30, 29, 30, 1, 24, 29 },
                { 0, 30, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 2, 12, 0 },
                { 0, 30, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 2, 1, 0 },
                { 2, 29, 30, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 1, 22, 29 },// 04
                { 0, 29, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 2, 9, 0 },
                { 7, 30, 29, 30, 29, 30, 29, 30, 30, 30, 29, 30, 30, 1, 29, 29 },// 06
                { 0, 29, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30, 2, 18, 0 },
                { 0, 30, 29, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 2, 7, 0 },
                { 5, 30, 30, 29, 29, 30, 29, 30, 29, 30, 29, 30, 30, 1, 26, 29 },// 09
                { 0, 30, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 2, 14, 0 },
                { 0, 30, 29, 30, 30, 29, 30, 29, 29, 30, 29, 30, 29, 2, 3, 0 },
                { 4, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 29, 30, 1, 23, 29 },// 12
                { 0, 30, 29, 30, 29, 30, 30, 29, 30, 29, 30, 29, 30, 2, 10, 0 },
                { 9, 29, 30, 29, 30, 29, 30, 29, 30, 30, 30, 29, 30, 1, 31, 29 },
                { 0, 29, 30, 29, 29, 30, 29, 30, 30, 30, 29, 30, 29, 2, 19, 0 },
                { 0, 30, 29, 30, 29, 29, 30, 29, 30, 30, 29, 30, 30, 2, 8, 0 },
                { 6, 29, 30, 29, 30, 29, 29, 29, 30, 29, 30, 30, 30, 1, 28, 30 },
                { 0, 29, 30, 29, 30, 29, 29, 30, 29, 30, 29, 30, 30, 2, 16, 0 },
                { 0, 30, 29, 30, 29, 30, 29, 29, 30, 29, 29, 30, 30, 2, 5, 0 },
                { 4, 29, 30, 30, 30, 30, 29, 29, 30, 29, 30, 29, 30, 1, 25, 29 } };

        int rYear = year - 1949;
        int rDay = 0;
        int i = 0;
        int months[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
        if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
            months[2] = 29;

        if (nong[year - 1949][13] > month)// 查找的月份小于春节的月份
        {

            rDay = months[1] - day + nong[rYear][14] - 1;
            for (i = 12; rDay >= 0; i--) {
                rDay = rDay - nong[rYear - 1][i];
                if (i == nong[rYear - 1][0] && rDay >= 0) {
                    if (nong[rYear - 1][15] == nong[rYear - 1][nong[rYear - 1][0]]) {
                        rDay = rDay - nong[rYear - 1][i];
                    } else {
                        rDay = rDay - nong[rYear - 1][i] - 1;
                        if (rDay > 0)
                            rDay = rDay + 1;
                    }
                }
            }
            year = year - 1;
            i = i + 1;
            rDay = Math.abs(rDay);

        }

        if (nong[rYear][13] == month)// 查找的月份等于春节的月份
        {
            if (nong[rYear][14] > day) {
                rDay = nong[rYear][14] - day - 1;

                rDay = rDay - nong[rYear - 1][12];
                rDay = Math.abs(rDay);
                year -= 1;

                i = 12;
            }
            if (nong[rYear][14] == day) {
                i = 1;
                rDay = 1;

            }
            if (nong[rYear][14] < day) {
                rDay = day - nong[rYear][14] + 1;
                i = 1;

            }

        }

        if (nong[rYear][13] < month) {
            for (i = nong[rYear][13] + 1; i < month; i++) { // 查找的月份大于春节的月份
                rDay = rDay + months[i];
            }
            rDay = rDay + months[nong[rYear][13]] - nong[rYear][14]
                                                                            + day;

            for (i = 1; rDay >= 0; i++) {
                rDay = rDay - nong[rYear][i];

                if (i == nong[rYear][0] && rDay >= 0) {
                    if (nong[rYear][15] == nong[rYear][nong[rYear][0]]) {
                        rDay = rDay - nong[rYear][15];
                    } else {
                        rDay = rDay - nong[rYear][15] - 1;
                        if (rDay > 0)
                            rDay = rDay + 1;
                    }
                }
            }
            i = i - 1;
            if (nong[rYear][i] == Math.abs(rDay)) {
                rDay = 1;
            } else
                rDay = nong[rYear][i] + rDay + 1;

        }
        NongDate[0] = year;
        NongDate[1] = i;
        NongDate[2] = rDay;
        NongDate[3] = nong[rYear][13];
        NongDate[4] = nong[rYear][14];

        return NongDate;
    }
  class  Filechange  extends  FocusAdapter  //右键菜单的可用判断
     { // 如果文本区没有选中的内容,则相应菜单项不可用
          public   void  focusLost(FocusEvent e)
          {
             String string  =  CenterText.getSelectedText();//获得被选中的文本
             if (string != "" && string != null )
              {
                pcut.setEnabled( true );
                pcopy.setEnabled( true );
                pdelete.setEnabled( true );
              }
             else                   //为空说明没有任何文本被选中 , 相应菜单不可用
               {
                pcut.setEnabled( false );
                pcopy.setEnabled( false );
                pdelete.setEnabled( false );   
            }            
        }
    }
 }