Java日历记事本课程设计报告

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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

相关文档
最新文档