您好,欢迎访问三七文档
运行界面://CalendarWindow类packageothers;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.util.*;importjava.io.*;importjava.awt.SplashScreen;publicclassCalendarWindowextendsJFrameimplementsActionListener,MouseListener,FocusListener{Calendarcalendar;intyear,month,day;CalendarMessagecalendarMessage;CalendarPadcalendarPad;NotePadnotePad;JTextFieldshowYear,showMonth;JTextFieldshowDay[];CalendarImagecalendarImage;Stringpicturename;//图像名称;StringgetPicture_address;Alarmalarm;JButtonnextYear,previousYear,nextMonth,previousMonth;JButtonsaveDailyRecord,deleteDailyRecord,readDailyRecord,changeBackground;Filedir;ColorbackColor=Color.white;publicCalendarWindow(){dir=newFile(./dailyRecord);dir.mkdir();showDay=newJTextField[42];for(inti=0;ishowDay.length;i++){showDay[i]=newJTextField();showDay[i].setBackground(backColor);showDay[i].setLayout(newGridLayout(3,3));showDay[i].addMouseListener(this);showDay[i].addFocusListener(this);}calendarMessage=newCalendarMessage();calendarPad=newCalendarPad();notePad=newNotePad();Calendarcalendar=Calendar.getInstance();calendar.setTime(newDate());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.setMessage(year,month,day);calendarPad.showMonthCalendar();doMark();calendarImage=newCalendarImage();picturename=getPicture_address();//calendarImage.setImageFile(newFile(picturename));alarm=newAlarm();JSplitPanesplitV1=newJSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarImage);JSplitPanesplitV2=newJSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,alarm);JSplitPanesplitH=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,splitV1,splitV2);add(splitH,BorderLayout.CENTER);showYear=newJTextField(+year,6);showYear.setFont(newFont(TimesRoman,Font.BOLD,12));showYear.setHorizontalAlignment(JTextField.CENTER);showMonth=newJTextField(+month,4);showMonth.setFont(newFont(TimesRoman,Font.BOLD,12));showMonth.setHorizontalAlignment(JTextField.CENTER);nextYear=newJButton(下年);previousYear=newJButton(上年);nextMonth=newJButton(下月);previousMonth=newJButton(上月);nextYear.addActionListener(this);previousYear.addActionListener(this);nextMonth.addActionListener(this);previousMonth.addActionListener(this);showYear.addActionListener(this);showMonth.addActionListener(this);JPanelnorth=newJPanel();north.add(previousYear);north.add(showYear);north.add(nextYear);north.add(previousMonth);north.add(showMonth);north.add(nextMonth);add(north,BorderLayout.NORTH);changeBackground=newJButton(更改背景图片);saveDailyRecord=newJButton(保存日志);deleteDailyRecord=newJButton(删除日志);readDailyRecord=newJButton(读取日志);changeBackground.addActionListener(this);saveDailyRecord.addActionListener(this);deleteDailyRecord.addActionListener(this);readDailyRecord.addActionListener(this);JPanelpSouth=newJPanel();pSouth.add(changeBackground);pSouth.add(saveDailyRecord);pSouth.add(deleteDailyRecord);pSouth.add(readDailyRecord);add(pSouth,BorderLayout.SOUTH);setVisible(true);setBounds(70,70,770,500);validate();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicStringgetPicture_address(){Stringaddress=null;try{FileInputStreamoutOne=newFileInputStream(picture_address.txt);ObjectInputStreamoutTwo=newObjectInputStream(outOne);try{address=(String)outTwo.readObject();}catch(Exceptionex){}outTwo.close();}catch(IOExceptioneee){}if(address!=null){returnaddress;}else{returnpicture.jpg;}}publicvoidactionPerformed(ActionEvente){if(e.getSource()==changeBackground){FileDialogdia=newFileDialog(this,选定图片,FileDialog.LOAD);//新建一个文件选择对话框,用dia获得选择得到的信息;dia.setModal(true);//设置为模态对话框;dia.setVisible(true);if((dia.getDirectory()!=null)&&(dia.getFile()!=null))//如果得到的路径和文件名不为空;{try{FileOutputStreaminOne=newFileOutputStream(picture_address.txt);ObjectOutputStreaminTwo=newObjectOutputStream(inOne);inTwo.writeObject(dia.getDirectory()+dia.getFile());inTwo.close();}catch(IOExceptionee){}picturename=getPicture_address();//从文件中读出显示图片的路径地址;calendarImage.setImageFile(newFile(picturename));//将获得路径传给图片,显示该路径指定的图片}}if(e.getSource()==nextYear){year++;showYear.setText(+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.setShowDayTextField(showDay);calendarPad.showMonthCalendar();notePad.setMessage(year,month,day);doMark();}elseif(e.getSource()==previousYear){year--;showYear.setText(+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.setShowDayTextField(showDay);calendarPad.showMonthCalendar();notePad.setMessage(year,month,day);doMark();}elseif(e.getSource()==nextMonth){month++;if(month12){month=1;year++;}showYear.setText(+year);showMonth.setText(+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.setShowDayTextField(showDay);calendarPad.showMonthCalendar();notePad.setMessage(year,month,day);doMark();}elseif(e.ge
本文标题:日历记事本程序代码
链接地址:https://www.777doc.com/doc-5795810 .html