精华内容
下载资源
问答
  • java日历记事本
    2021-01-19 14:17:09

    展开全部

    1、可以使用简单的数据库,如Sql Server, MySql ,等(这个需要在Java JDK中添e5a48de588b662616964757a686964616f31333332633062加链接数据库的jar包,或者将对应的jar包加到你的Java Project中);

    2、可以考虑使用Java的简单存储,如下:import java.awt.event.ActionEvent;

    import java.awt.event.ActionListener;

    import java.io.File;

    import java.io.RandomAccessFile;

    import javax.swing.JButton;

    import javax.swing.JFrame;

    import javax.swing.JOptionPane;

    public class S extends JFrame implements ActionListener {

    private static final long serialVersionUID = 1L;

    private JButton jb = null;

    private int i = 0;

    public void init() {

    jb = new JButton("保存");

    jb.addActionListener(this);

    }

    public S() {

    init();

    this.setLayout(null);

    this.setSize(800, 600);

    this.setVisible(true);

    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.add(jb).setBounds(100, 200, 120, 60);

    }

    // path为保存文件路径,content为输入框内容

    public void Save(String path, String content) {

    File file = new File(path);

    if (!file.exists()) {

    file.mkdir();

    }

    if (file.isDirectory()) {

    file.delete();

    return ;

    }

    RandomAccessFile raf = null;

    try {

    raf = new RandomAccessFile(file, "rw");

    raf.write(content.getBytes("GBK"));  //将内容写入到固定位置的文件

    raf.close();

    } catch (Exception e) {

    e.printStackTrace();

    }

    }

    @Override

    public void actionPerformed(ActionEvent e) {

    // TODO Auto-generated method stub

    if (e.getSource() == jb) {

    String content = JOptionPane.showInputDialog("");

    if (content != null) {

    i++;

    String path = "D:\\C" + i + ".txt";

    Save(path.trim(), content); // 保存到你要保存的位置

    } else {

    //这里还可以做其他操作

    JOptionPane.showConfirmDialog(getParent(), "请输入需要保存的内容!");

    }

    }

    }

    @SuppressWarnings("unused")

    public static void main(String[] args) {

    // TODO Auto-generated method stub

    S s = new S();

    }

    }

    更多相关内容
  • Java 日历记事本课程设计报告 在设计日历记事本时需要编写 6个JAVA源文件和 效果图如下 . CalendarWindow 类 import ; import ; import ; import ; implementspublic class CalendarWindow extends JFrame ...
  • java日历记事本java日历记事本
  • 信息与计算科学专业课程设计 用Java实现日历记事本 1. 实验目的 掌握RandomAccessFile类的使用掌握字符输入输出流和缓冲输入输出流的使用 2. 实验要求 实验前应事先熟悉相关知识点拟出相应的实验操作步骤明确实验...
  • java实现日历记事本

    2018-08-22 11:10:35
    日历记事本实现了在某一日期记录事件心情的功能,同时还具有增,删,改,查的功能。适用于初学者,代码很全,可以在英文版的eclips上运行
  • java 日历记事本

    2016-12-22 15:38:50
    导入项目后别忘了 添加外部归档(构建路径) 所需包文件在resources中
  • java日历记事本

    2022-04-07 10:00:30
    /* * To change this template, choose ...package 日历记事本; /** * * @author Administrator */ import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Year extends Box imple.
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package 日历记事本;
    
    /**
     *
     * @author Administrator
     */
    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("TimesRomn",Font.BOLD,14)); 
         this.日历=日历;
         year=日历.getYear();
         明年=new JButton("下年");
         去年=new JButton("上年");
         add(去年);
         add(showYear);
         add(明年);
         showYear.addActionListener(this);
         去年.addActionListener(this);
         明年.addActionListener(this);
      }
     public void setYear(int year)
      {
        this.year=year;
        showYear.setText(""+year);
      }
     public int getYear()
      {
        return year;
      } 
     public void actionPerformed(ActionEvent e)
      {
        if(e.getSource()==去年)
          {
            year=year-1;
            showYear.setText(""+year);
            日历.setYear(year);
            日历.设置日历牌(year,日历.getMonth());
          }
        else if(e.getSource()==明年)
          {
            year=year+1;
            showYear.setText(""+year);
            日历.setYear(year);
            日历.设置日历牌(year,日历.getMonth());
          }
        else if(e.getSource()==showYear)
          {
             try
                {
                  year=Integer.parseInt(showYear.getText());
                  showYear.setText(""+year);
                  日历.setYear(year);
                  日历.设置日历牌(year,日历.getMonth());
                }
             catch(NumberFormatException ee)
                {
                  showYear.setText(""+year);
                  日历.setYear(year);
                  日历.设置日历牌(year,日历.getMonth());
                }
          }
      }   
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package 日历记事本;
    
    /**
     *
     * @author Administrator
     */
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class Month extends Box implements ActionListener
    {
      int month;                           
      JTextField showMonth=null;           
      JButton 下月,上月;
      CalendarPad 日历;
      public Month(CalendarPad 日历)
      {  
         super(BoxLayout.X_AXIS);        
         this.日历=日历;
         showMonth=new JTextField(2);
         month=日历.getMonth();
         showMonth.setEditable(false);
         showMonth.setForeground(Color.blue);
         showMonth.setFont(new Font("TimesRomn",Font.BOLD,16)); 
         下月=new JButton("下月");
         上月=new JButton("上月");
         add(上月);
         add(showMonth);
         add(下月);
         上月.addActionListener(this);
         下月.addActionListener(this);
         showMonth.setText(""+month);
      }
     public void setMonth(int month)
      {
        if(month<=12&&month>=1)
          {
           this.month=month;
          }
        else
          {
            this.month=1;
          }
        showMonth.setText(""+month);
      }
     public int getMonth()
      {
        return month;
      } 
     public void actionPerformed(ActionEvent e)
      {
        if(e.getSource()==上月)
          {
            if(month>=2)
             {
                month=month-1;
                日历.setMonth(month);
                日历.设置日历牌(日历.getYear(),month);
             }
            else if(month==1)
             {
                month=12;
                日历.setMonth(month);
                日历.设置日历牌(日历.getYear(),month);
             }
           showMonth.setText(""+month);
          }
        else if(e.getSource()==下月)
          {
            if(month<12)
              {
                month=month+1;
                日历.setMonth(month);
                日历.设置日历牌(日历.getYear(),month);
              }
            else if(month==12)
              {
                month=1;
                日历.setMonth(month);
                日历.设置日历牌(日历.getYear(),month);
              }
            showMonth.setText(""+month);
          }
      }   
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package 日历记事本;
    
    /**
     *
     * @author Administrator
     */
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    
    public class NotePad extends JPanel implements ActionListener
    {
      JTextArea text;              
      JButton 保存日志,删除日志;
      Hashtable table;             
      JLabel 信息条;               
      int year,month,day;          
      File file;                   
      CalendarPad calendar;
      public  NotePad(CalendarPad calendar)
       {
         this.calendar=calendar;
         year=calendar.getYear();
         month=calendar.getMonth();
         day=calendar.getDay();;
         table=calendar.getHashtable();
         file=calendar.getFile();
         信息条=new JLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER);
         信息条.setFont(new Font("TimesRoman",Font.BOLD,16));
         信息条.setForeground(Color.blue);
         text=new JTextArea(10,10);
         保存日志=new JButton("保存日志") ;
         删除日志=new JButton("删除日志") ;
         保存日志.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(""+year+"年"+month+"月"+day+"日");
       }
      public void 设置文本区(String s)
       {
         text.setText(s);
       }
      public void 获取日志内容(int year,int month,int day)
       {
           String key=""+year+""+month+""+day;
           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=""+year+"年"+month+"月"+day+"这一天有日志记载,想看吗?";
                int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
                                                   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=""+year+""+month+""+day;
            
            String m=""+year+"年"+month+"月"+day+"保存日志吗?";
            int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
                                                   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.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=""+year+""+month+""+day;
             if(table.containsKey(key))
              {  
                String m="删除"+year+"年"+month+"月"+day+"日的日志吗?";
                int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,
                                                   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();
                     out.close();
                     text.setText(null);
                    }
                   catch(Exception ee)
                    {
                    }
                  }
              }
            else
              {
                
                String m=""+year+"年"+month+"月"+day+"无日志记录";
                JOptionPane.showMessageDialog(this,m,"提示",JOptionPane.WARNING_MESSAGE);
              }
       }
    
    }
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package 日历记事本;
    
    /**
     *
     * @author Administrator
     */
    import java.util.Calendar;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.Hashtable;
    public class CalendarPad extends JFrame implements MouseListener
    {
       int year,month,day;
       Hashtable hashtable;             
       File file;                       
       JTextField showDay[];             
       JLabel title[];                   
       Calendar 日历;
       int 星期几; 
       NotePad notepad=null;             
       Month 负责改变月;
       Year  负责改变年;
       String 星期[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
       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;
         负责改变年=new Year(this);
         负责改变年.setYear(year);
         负责改变月=new Month(this);
         负责改变月.setMonth(month);
      
         title=new JLabel[7];                         
         showDay=new JTextField[42];                   
         for(int j=0;j<7;j++)                         
           {
             title[j]=new JLabel();
             title[j].setText(星期[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]);
           }
             
         日历=Calendar.getInstance();
         Box box=Box.createHorizontalBox();          
         box.add(负责改变年);
         box.add(负责改变月);
         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();
        
         hashtable=new Hashtable();
         file=new File("日历记事本.txt");
          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);
         
         设置日历牌(year,month);
         addWindowListener(new WindowAdapter()
                        { public void windowClosing(WindowEvent e)
                           {
                             System.exit(0);
                           }
                        });
        setVisible(true);
        setBounds(100,50,524,285);
        validate();
       }
      public void 设置日历牌(int year,int month)
       {
         日历.set(year,month-1,1);              
         
         星期几=日历.get(Calendar.DAY_OF_WEEK)-1;
         if(month==1||month==2||month==3||month==5||month==7
                            ||month==8||month==10||month==12)
            {
                排列号码(星期几,31);         
            }
         else if(month==4||month==6||month==9||month==11)
            {
                排列号码(星期几,30);
            }
         else if(month==2)
            {
             if((year%4==0&&year%100!=0)||(year%400==0))  
               {
                 排列号码(星期几,29);
               }
             else
               {
                 排列号码(星期几,28);
               }
           }
       } 
      public void 排列号码(int 星期几,int 月天数)
       {
          for(int i=星期几,n=1;i<星期几+月天数;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<星期几;i++)
                 {
                    showDay[i].setText("");
                 }
           for(int i=星期几+月天数;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.设置信息条(year,month,day);
             notepad.设置文本区(null);
             notepad.获取日志内容(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);
       }
    }  

    展开全文
  • java日历记事本程序

    2013-03-12 16:04:53
    netbeans项目 日历+记事本+课程表+计时提醒功能+导出导入课程列表
  • 题目: 日历记事本 学生姓名: 学号: 班级: 题目类型:软件工程(R) 指导教师: 一. 题目简介 该设计要求设计一个带有日程提醒功能的日历。 通过该题目的设计,培养学生面向对象程序设计的思想,要求学生达到...
  • 面向对象程序设计 课程设计报告 题 目 电子日历记事本的设计 院 系 信息科学与工程学院 专业班级 计算机科学与技术 1201 班 学生姓名 程伟 学 号 20121183011 指导教师 吴奕 20 14 年 12 月 29 日至 20 15 年 1 月 9...
  • Java日历记事本

    2021-06-14 11:56:58
    java课程设计日历记事本 package coursedesign; import java.util.*; import java.io.*; import java.awt.*; import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; public class ...

    java课程设计日历本记事本

    import java.util.*;
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    
    public class CalenderNoteFrame extends JFrame implements ActionListener, DocumentListener{
    	JButton lastyear, nextyear, lastmonth, nextmonth, saverecord, deleterecord, readrecord;
    	JTextField writeyear, writemonth;
    	JLabel showdata;
    	JTextArea writerecord;
    	JButton[] weekButton=new JButton[7];	
    	JButton[] daysButton=new JButton[42];	//创建日期按钮
    	String year, month;
    	CalenderNoteFrame(){		//构造函数
    		setTitle("日历记事本");
    		setVisible(true);
    		setBounds(100,100,1000,600);
    		setDefaultCloseOperation(EXIT_ON_CLOSE);
    		inti();
    		validate();
    	}
    	void inti(){
    		Container allPanel = getContentPane();		
    		allPanel.setLayout(new BorderLayout());		//整体采用BorderLayout布局
            JPanel leftPanel=new JPanel();
            leftPanel.setLayout(new GridLayout(7, 7));		//日历表采用GirdLayout布局
            String[] week={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
            Font font=new Font("宋体",Font.BOLD, 15);
            for(int i=0;i<week.length;i++){				//添加星期和日期按钮
                weekButton[i]=new JButton(week[i]);
                weekButton[i].setFont(font);
                weekButton[i].setEnabled(false);		//
                leftPanel.add(weekButton[i]);
            }
            for( int i=0;i<42;i++){
                daysButton[i]=new JButton("");
                daysButton[i].setSize(1, 1);
                leftPanel.add(daysButton[i]);
            }
            allPanel.add(leftPanel,BorderLayout.WEST);
            Date nowtime = new Date();
            String nowyear = String.format("%tY", nowtime);
            String nowmonth = String.format("%tm", nowtime);
            if(nowmonth.substring(0, 1).compareTo("0") == 0) {
            	nowmonth = nowmonth.substring(1, 2);		//如果月份为个位数,去掉前面的0
            }
            writeyear = new JTextField(nowyear,5);
            writemonth = new JTextField(nowmonth,5);
            CalclulateDate();
            flag();
    		lastyear = new JButton("上年");
    		nextyear = new JButton("下年");
    		lastmonth = new JButton("上月");
    		nextmonth = new JButton("下月");
    		JPanel upPanel = new JPanel(new FlowLayout());
    		upPanel.add(lastyear);
    		upPanel.add(writeyear);
    		upPanel.add(nextyear);
    		upPanel.add(lastmonth);
    		upPanel.add(writemonth);
    		upPanel.add(nextmonth);
    		allPanel.add(upPanel,BorderLayout.NORTH);
    		Box centerPanel = Box.createVerticalBox();
    		String strnowday = String.format("%td", nowtime);
    		if(strnowday.substring(0, 1).compareTo("0") == 0) {			//如果当前日期为个位数, 去掉前面的0
    			strnowday = strnowday.substring(1, 2);				
    		}
    		showdata = new JLabel(nowyear+"-"+nowmonth+"-"+strnowday);
    		writerecord = new JTextArea();
    		showdata.setFont(font);
    		writerecord.setLineWrap(true);
    		writerecord.setWrapStyleWord(true);
    		writerecord.setFont(new Font("黑体",Font.BOLD,18));
    		centerPanel.add(showdata);
    		centerPanel.add(writerecord);
    		allPanel.add(centerPanel, BorderLayout.CENTER);
    		JPanel downPanel = new JPanel(new FlowLayout());
    		saverecord = new JButton("保存日志");
    		deleterecord = new JButton("删除日志");
    		readrecord = new JButton("读取日志");
    		downPanel.add(saverecord);
    		downPanel.add(deleterecord);
    		downPanel.add(readrecord);
    		allPanel.add(downPanel, BorderLayout.SOUTH);
    		lastyear.addActionListener(this);
    		nextyear.addActionListener(this);
    		lastmonth.addActionListener(this);
    		nextmonth.addActionListener(this);
    		saverecord.addActionListener(this);
    		deleterecord.addActionListener(this);
    		readrecord.addActionListener(this);
    		(writeyear.getDocument()).addDocumentListener(this);	//为writeyear文本框添加文件监视器
    		(writemonth.getDocument()).addDocumentListener(this);
    	}
    public void actionPerformed(ActionEvent e) {
    		if(e.getSource() == lastyear) {
    			int tempyear;
    			tempyear = Integer.parseInt(writeyear.getText());
    			year = String.valueOf(tempyear-1);		//点击lastyear按钮后,年份减一
    			writeyear.setText(year);
    		}
    		
    		if(e.getSource() == nextyear) {
    			int tempyear;
    			tempyear = Integer.parseInt(writeyear.getText());
    			year = String.valueOf(tempyear+1);
    			writeyear.setText(year);
    		}
    		
    		if(e.getSource() == lastmonth) {
    			int tempmonth;
    			tempmonth = Integer.parseInt(writemonth.getText());
    			if(tempmonth == 1) {	//如果月份为1时,重置月份为12,并调用lastyear事件
    				e.setSource(lastyear);
    				actionPerformed(e);
    				tempmonth = 12;
    				month = String.valueOf(tempmonth);
    				writemonth.setText(month);
    			}
    			else {
    				month = String.valueOf(tempmonth-1);
    				writemonth.setText(month);
    			}
    		}
    		
    		if(e.getSource() == nextmonth) {
    			int tempmonth;
    			tempmonth = Integer.parseInt(writemonth.getText());
    			if(tempmonth == 12) {
    				tempmonth = 0;
    				e.setSource(nextyear);
    				actionPerformed(e);
    			}
    			month = String.valueOf(tempmonth+1);
    			writemonth.setText(month);
    		}
    		
    		
    		for(int i=0; i<42; i++) {
    			if(e.getSource() == daysButton[i]) {
    				year=(String)writeyear.getText();//获得点击的年份
    	            month=(String)writemonth.getText();//获得点击的月份
    	            String chosedate = year+"-"+month+"-"+daysButton[i].getText();		//点击日期按钮设置showdata显示
    	            int index = chosedate.lastIndexOf("(");
    	            if(index>0) {
    	            	showdata.setText(chosedate.substring(0, index));
    	            }
    	            else {
    	            	showdata.setText(chosedate);
    	            }
    	            writerecord.setText(null);
    			}
    		}
    		
    		if(e.getSource() == saverecord) {
    			try {
    				String strfile = showdata.getText();
    				String mess = writerecord.getText();
    				File file = new File(strfile+".txt");
    				file.createNewFile();
    				FileWriter fw = new FileWriter(file);
    				fw.write(mess);
    				fw.close();
    				flag();				//标记有日志的日期按钮
    				JOptionPane.showMessageDialog(this, "保存成功!","提示框",JOptionPane.WARNING_MESSAGE);
    			}
    			catch(Exception e1) {
    				JOptionPane.showMessageDialog(this, e1.getMessage(),"提示框",JOptionPane.WARNING_MESSAGE);
    			}
    		}
    		
    		if((e.getSource() == readrecord)) {
    			 try {
    				 writerecord.setText(null);
    				 String readfile = showdata.getText();
    				 File file = new File(readfile+".txt");
    				 FileReader fi = new FileReader(file);
    				 BufferedReader br = new BufferedReader(fi);	//使用文件缓冲区类
    				 String line;
    				 while((line = br.readLine()) != null) {		//按行读取文件内容
    					 writerecord.setText(writerecord.getText() + line);
    				 }
    				 fi.close();
    			 }
    			 catch(Exception e2) {
    				 JOptionPane.showMessageDialog(this, "此日期无记录", "提示框",JOptionPane.WARNING_MESSAGE);
    			 }
    		}
    		
    		if(e.getSource() == deleterecord) {
    			try {
    				String deletefile = showdata.getText();
    				File file = new File(deletefile+".txt");
    				if(!file.exists()) {
    					JOptionPane.showMessageDialog(this, "此日期无记录", "提示框",JOptionPane.WARNING_MESSAGE);
    				}
    				else {
    					file.delete();
    					writerecord.setText(null);
    					CalclulateDate();
    					flag();
    					JOptionPane.showMessageDialog(this, "删除成功", "提示框",JOptionPane.WARNING_MESSAGE);
    				}
    			}
    			catch(Exception e3) {
    				JOptionPane.showMessageDialog(this, e3.getMessage(), "提示框",JOptionPane.WARNING_MESSAGE);
    			}
    		}
    	}
    	
    	
    	
    	public void changedUpdate(DocumentEvent e) {
    
    	}
    	public void removeUpdate(DocumentEvent e) {
    
    	}
    	public void insertUpdate(DocumentEvent e) {		//当writeyear或者writeday变化时执行事件
    		CalclulateDate();		//显示当前月份日历
    		flag();
    	}
    	
    	public int calclulate(int year,int month){//计算月份的天数
            int day;
            if(((year%4==0&&year%100!=0)||year%400==0) && month==2){
                day=29;
                return day;
            }
            if(month==1||month==3||month==5||month==5||month==7||month==8||month==10||month==12){
                day=31;
            }else{
                day = month==2 ? 28 : 30;
            }
            return day;
        }
    	
    	
    	public void CalclulateDate() {
    		for(int i=0;i<daysButton.length;i++){//初始时清空所有按钮的数字,以及设置为不可选
                daysButton[i].setBackground(null);
                daysButton[i].setText("");
                daysButton[i].setEnabled(false);
            }
            year=(String)writeyear.getText();//获得点击的年份
            month=(String)writemonth.getText();//获得点击的月份
            Calendar ca=Calendar.getInstance();
            ca.set(Integer.parseInt(year),Integer.parseInt(month)-1, 1);
            int day=ca.get(Calendar.DAY_OF_WEEK)-1;//减一是因为从星期天开始算,星期天=1
            for(int i=1;i<=calclulate(Integer.parseInt(year),Integer.parseInt(month));i++){
                daysButton[day].setText(""+i+"");
                daysButton[day].setEnabled(true);
                daysButton[day].addActionListener(this);
                day++;
            }
    	}
    	
    	public void flag() {
            for(int j=0; j<42; j++) {
            	year=(String)writeyear.getText();		//获得点击的年份
                month=(String)writemonth.getText();		//获得点击的月份 
                String searchfile = year+"-"+month+"-"+daysButton[j].getText();
                File ffile = new File(searchfile+".txt");
                if(ffile.exists() && daysButton[j].getText().length()<3) {
                	daysButton[j].setText(daysButton[j].getText()+"(有)");
                }
            }
    	}
    }
    

    此次课程设计主要难点在于星期与日期对应并显示每个月的日期。还有就是文件管理的应用,对读写的操作不太熟悉并花费了大量时间。此次也参考了其他文章
    在此感谢。

    展开全文
  • Java日历记事本.doc

    2022-06-26 10:06:55
    Java日历记事本.doc
  • import java.util.Calendar;import javax.swing.*;import javax.swing.text.JTextComponent;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.Hashtable;public class CalendarPad ext...

    import java.util.Calendar;

    import javax.swing.*;

    import javax.swing.text.JTextComponent;

    import java.awt.*;

    import java.awt.event.*;

    import java.io.*;

    import java.util.Hashtable;

    public class CalendarPad extends JFrame implements MouseListener

    {

    int year,month,day;

    Hashtable hashtable;

    File file;

    JTextField showDay[];

    JLabel title[];

    Calendar rili;

    int xqj;

    NotePad notepad=null;

    Month changmonth;

    Year changyear;

    String xq[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

    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;

    changyear=new Year(this);

    changyear.setYear(year);

    changmonth=new Month(this);

    changmonth.setMonth(month);

    title=new JLabel[7];

    showDay=new JTextField[42];

    for(int j=0;j<7;j++)

    {

    title[j]=new JLabel();

    title[j].setText(xq[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]);

    }

    rili=Calendar.getInstance();

    Box box=Box.createHorizontalBox();

    box.add(changyear);

    box.add(changmonth);

    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();

    hashtable=new Hashtable();

    file=new File("日历记事本.txt");

    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);

    srili(year,month);

    addWindowListener(new WindowAdapter()

    { public void windowClosing(WindowEvent e)

    {

    System.exit(0);

    }

    });

    setVisible(true);

    setBounds(100,50,524,285);

    validate();

    }

    public void srili(int year,int month)

    {

    rili.set(year,month-1,1);

    xqj=rili.get(Calendar.DAY_OF_WEEK)-1;

    if(month==1||month==2||month==3||month==5||month==7

    ||month==8||month==10||month==12)

    {

    num(xqj,31);

    }

    else if(month==4||month==6||month==9||month==11)

    {

    num(xqj,30);

    }

    else if(month==2)

    {

    if((year%4==0&&year%100!=0)||(year%400==0))

    {

    num(xqj,29);

    }

    else

    {

    num(xqj,28);

    }

    }

    }

    public void num(int xqj,int days)

    {

    for(int i=xqj,n=1;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

    {

    showDay[i].setText("");

    }

    for(int i=xqj+days;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.setxinxitiao(year,month,day);

    notepad.settext(null);

    notepad.savemessage(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)

    {

    }

    }

    展开全文
  • JAVA日历记事本课程设计报告
  • java日历记事本小程序

    2008-07-12 17:40:05
    这是用JAVA写的日历记事本小程序,喜欢的就分享一下吧
  • Java 日历记事本课程设计报告 在 设 计 日历 记 事 本 时 需要 编 写 6 个 JAVA 源 文 件 CalendarWindow.java CalendarPad.java NotePad.java CalendarImage.javaClock.java和CalendarMesssage.java 效果图如下 ....
  • 北京师范大学20152016 学年春季学期期末Java 程序设计作业试 卷 课程名称 Java 程序设计 任课教师姓名 孙一 林 卷面总分 100 分 考试时长 分钟 考试类别闭 卷 开卷 其他 院系 信息科学与技术学院 专 业 计算机科学与...
  • java日历记事本(无敌版带提醒功能调整时区更换图片铃声功能).doc
  • 日历记事本java

    2021-06-14 10:06:36
    ca.java package clander; import java.io.*; import java.awt.*; import java.awt.event.*; import java.util.*; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java....
  • java-日历记事本

    千次阅读 多人点赞 2020-07-27 10:42:42
    java-日历记事本 功能还不完善,能毕业就行.jpg package com.company; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.BufferedReader; import ...
  • java课程设计日历记事本赵锐.doc 2本科生课程设计课程名称JAVA程序设计课程设计题目日历记事本学号201440930252学生姓名赵锐所在专业2014计算机学院所在班级信工2班成绩课程设计时间2017年5月日2017年5月日1目录1...
  • Java日历记事本!!!!!!!!!!!!!!!!!
  • 基于JAVA日历记事本

    2011-01-13 16:14:17
    实例使用Swing和AWT实现一个图形化的日历记事本,可以查看星期、日期、月份、和年份,还有可以随时记录和保存当天的日志。

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 2,377
精华内容 950
关键字:

java日历记事本

友情链接: hough.rar