JAVA日历记事本课程设计报告
- 格式:doc
- 大小:171.50 KB
- 文档页数:23
Java日历记事本课程设计报告
在设计日历记事本时,需要编写6个JA V A源文件:CalendarWindow.java、CalendarPad.java、NotePad.java、CalendarImage.java、Clock.java和CalendarMesssage.java
效果图如下
. CalendarWindow类
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
public class CalendarWindow extends JFrame implements ActionListener,MouseListener,FocusListener{
int year,month,day;
CalendarMessage calendarMessage;
CalendarPad calendarPad;
NotePad notePad;
JTextField showYear,showMonth;
JTextField[] showDay;
CalendarImage calendarImage;
String picturename;
Clock clock;
JButton nextYear,previousYear,nextMonth,previousMonth;
JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;
JButton getPicture;
File dir;
Color backColor=Color.white ;
public CalendarWindow(){
dir=new File("./dailyRecord");
dir.mkdir();
showDay=new JTextField[42];
for(int i=0;i showDay[i]=new JTextField(); showDay[i].setBackground(backColor); showDay[i].setLayout(new GridLayout(3,3)); showDay[i].addMouseListener(this); showDay[i].addFocusListener(this); } calendarMessage=new CalendarMessage(); calendarPad=new CalendarPad(); notePad=new NotePad(); Calendar calendar=Calendar.getInstance(); calendar.setTime(new Date()); year=calendar.get(Calendar.YEAR); month=calendar.get(Calendar.MONTH)+1; day=calendar.get(Calendar.DAY_OF_MONTH); calendarMessage.setYear(year); calendarMessage.setMonth(month); calendarMessage.setDay(day); calendarPad.setCalendarMessage(calendarMessage); calendarPad.setShowDayTextField(showDay); notePad.setShowMessage(year,month,day); calendarPad.showMonthCalendar(); doMark(); calendarImage=new CalendarImage(); calendarImage.setImageFile(new File("flower.jpg")); clock=new Clock(); JSplitPane splitV1=new JSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarImage); JSplitPane splitV2=new JSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,clock); JSplitPane splitH=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,splitV1,splitV2); add(splitH,BorderLayout.CENTER); showYear=new JTextField(""+year,6); showYear.setFont(new Font("TimesRoman",Font.BOLD,12)); showYear.setHorizontalAlignment(JTextField.CENTER); showMonth=new JTextField(""+month,4); showMonth.setFont(new Font("TimesRoman",Font.BOLD,12)); showMonth.setHorizontalAlignment(JTextField.CENTER); nextYear=new JButton("下年"); previousYear=new JButton("上年"); nextMonth=new JButton("下月"); previousMonth=new JButton("上月"); nextYear.addActionListener(this); previousYear.addActionListener(this); nextMonth.addActionListener(this); previousMonth.addActionListener(this); JPanel north=new JPanel(); north.add(previousYear); north.add(showYear); north.add(nextYear); north.add(previousMonth); north.add(showMonth); north.add(nextMonth); add(north,BorderLayout.NORTH); saveDailyRecord=new JButton("保存日志"); deleteDailyRecord=new JButton("删除日志"); readDailyRecord=new JButton("读取日志"); saveDailyRecord.addActionListener(this); deleteDailyRecord.addActionListener(this); readDailyRecord.addActionListener(this); JPanel pSouth=new JPanel(); pSouth.add(saveDailyRecord); pSouth.add(deleteDailyRecord); pSouth.add(readDailyRecord); add(pSouth,BorderLayout.SOUTH); getPicture=new JButton("选择日历图像"); getPicture.addActionListener(this); pSouth.add(getPicture); add(pSouth,BorderLayout.SOUTH); setVisible(true); setBounds(60,60,660,480); validate(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);