用Java实现日历记事本
- 格式:doc
- 大小:296.50 KB
- 文档页数:27
《动态网站基础程序设计》课程设计班级:学号:姓名:课题:日历记事本指导教师:答辩日期:2017年8月30日一、任务描述阐述老师布置的课题、要求、最终实现结果。
(要紧密和老师沟通)设计题目:日历记事本设计要求:1.类之间的关系如图1-1所示。
(添加类图)图1-1 类之间的关系2.java源文件及其功能如表1-1所示。
表1-1 java源文件及其功能系统详细设计主类CalendarPad1.成员变量成员变量描述变量类型名称年、月、日int Year,month,day保存日志的散列表Hashtable hashtable存放散列表的文件File file显示日期JTextField[] showDay日历对象Calendar 日历记事本对象NotePad notepad月Month 负责改变月年Year 负责改变年2.方法名称功能备注CalendarPad 创建程序主窗口构造方法设置日历牌设置日历的年份、月份排列号码排列月份中的号码mousePressed 处理MouseEvent事件接口方法mian 程序开始运行记事本NotePad1.成员变量描述变量类型名称文本输入区JTextArea text保存、删除日志的按钮Button 保存日志、删除日志保存日志的散列表Hashtable table保存散列表的文件File file记录日志的年、月、日int year,month,day 2.方法名称功能备注NotePad 创建记事本对象构造方法setYear 设置年份getYear 获取年份setMonth 设置月份getMonth 获取月份setDay 设置日期getDay 获取日期获取日志内容获取日志内容保存日志保存日志删除日志删除日志actionPerformed 处理ActionEvent事件接口方法年Year1.成员变量描述变量类型名称int year表示年份的整数(负数表示公元前)显示年份的文本条JTextField showYear负责增减年份的按钮JButton 明年,去年2.方法名称功能备注Year 创建“年”对象构造方法setYear 设置年份getYear 获取年份actionPerformed 处理ActionEvent事件接口方法月Month1.成员变量描述变量类型名称int month表示月份的整数(负数表示公元前)显示月份的文本条JTextField ShowMonth负责增减月份的按钮JButton 上月,下月2.方法名称功能备注Month 创建“月”对象构造方法set Month 设置月份get Month 获取月份actionPerformed 处理ActionEvent事件接口方法二、任务分析针对老师的课题,谈谈为了实现课题内容,进行的分析。
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.length;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);}public void actionPerformed(ActionEvent e){if(e.getSource()==nextYear){year++;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousYear){year--;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==nextMonth){month++;if(month<1) month=12;showMonth.setText(""+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousMonth){month--;if(month<1) month=12;showMonth.setText(""+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==showYear){String s=showYear.getText().trim();char a[]=s.toCharArray();boolean boo=false;for(int i=0;i<a.length;i++)if(!(Character.isDigit(a[i])))boo=true;if(boo==true)JOptionPane.showMessageDialog(this, "您输入了非法年份","警告",JOptionPane.WARNING_MESSAGE);else if(boo==false)year=Integer.parseInt(s);showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==saveDailyRecord){notePad.save(dir,year,month,day);doMark();}else if(e.getSource()==deleteDailyRecord){notePad.delete(dir,year,month,day);doMark();}else if(e.getSource()==readDailyRecord){notePad.read(dir,year,month,day);}else if (e.getSource() ==getPicture ) {FileDialog fd=new FileDialog(this,"打开文件对话框");fd.setVisible(true);String fileopen = null, filename = null;fileopen = fd.getDirectory();filename = fd.getFile();calendarImage.setImageFile(new File(fileopen,filename));}}public void mousePressed(MouseEvent e){JTextField text=(JTextField)e.getSource();String str=text.getText().trim();try{ day=Integer.parseInt(str);}catch(NumberFormatException exp){}calendarMessage.setDay(day);notePad.setShowMessage(year,month,day);}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}public void mouseClicked(MouseEvent e){}public void focusGained(FocusEvent e){Component com=(Component)e.getSource();com.setBackground(Color.pink);}public void focusLost(FocusEvent e){Component com=(Component)e.getSource();com.setBackground(backColor);}public void doMark(){for(int i=0;i<showDay.length;i++){showDay[i].removeAll();String str=showDay[i].getText().trim();try{int n=Integer.parseInt(str);if(isHaveDailyRecord(n)==true){JLabel mess=new JLabel("有");mess.setFont(new Font("TimesRoman",Font.PLAIN,11));mess.setForeground(Color.blue);showDay[i].add(mess);}}catch(Exception exp){}}calendarPad.repaint();calendarPad.validate();}public boolean isHaveDailyRecord(int n){String key=""+year+""+month+""+n;String [] dayFile=dir.list();boolean boo=false;for(int k=0;k<dayFile.length;k++){if(dayFile[k].equals(key+".txt")){boo=true;break;}}return boo;}public String getPicture_address() {String address = null;try {InputStream outOne = new FileInputStream("picture_address.txt");ObjectInputStream outTwo = new ObjectInputStream(outOne);try {address = (String) outTwo.readObject();} catch (Exception ex) {}outTwo.close();} catch (IOException eee) {}if (address != null) {return address;} else {return "picture.jpg";}}public void actionPerformed1(ActionEvent e) {if (e.getActionCommand().equals("更改图片背景")) {FileDialog dia = new FileDialog(this, "选择图片", FileDialog.LOAD);dia.setModal(true);dia.setVisible(true);if ((dia.getDirectory() != null) && (dia.getFile() != null)) {try {FileOutputStream inOne = new FileOutputStream("picture_address.txt");ObjectOutputStream inTwo = new ObjectOutputStream(inOne);inTwo.writeObject(dia.getDirectory() + dia.getFile());inTwo.close();} catch (IOException ee) {}String picturename = getPicture_address();calendarImage.setImageFile(new File(picturename));}}public static void main(String args[]){new CalendarWindow();}}CalendarPad类import javax.swing.*;import java.awt .*;import java.awt.event.*;import java.util.*;import javax.swing.JPanel;public class CalendarPad extends JPanel{int year,month,day;CalendarMessage calendarMessage;JTextField[] showDay;JLabel title[];String[] 星期={"SUN 日","MON 一","TUE 二","WED 三","THU 四","FRI 四","SAT 六"};JPanel north,center;public CalendarPad(){setLayout(new BorderLayout());north=new JPanel();north.setLayout(new GridLayout(1,7));center=new JPanel();center.setLayout(new GridLayout(6,7));add(center ,BorderLayout.CENTER );add(north,BorderLayout.NORTH );title=new JLabel[7];for(int j=0;j<7;j++){title[j]=new JLabel();title[j].setFont(new Font("TimesRoman",Font.BOLD ,12));title[j].setText(星期[j]);title[j].setHorizontalAlignment(JLabel.CENTER);title[j].setBorder(BorderFactory.createRaisedBevelBorder());north.add(title[j]);}title[0].setForeground(Color.red);title[6].setForeground(Color.blue);}public void setShowDayTextField(JTextField[]text){showDay=text;for(int i=0;i<showDay.length;i++){showDay[i].setFont(new Font("TimesRoman",Font.BOLD ,15));showDay[i].setHorizontalAlignment(JTextField.CENTER);showDay[i].setEditable(false);center.add(showDay[i]);}}public void setCalendarMessage (CalendarMessage calendarMessage){ this.calendarMessage=calendarMessage;}public void showMonthCalendar(){String[] a=calendarMessage.getMonthCalendar();for(int i=0;i<42;i++)showDay[i].setText(a[i]);validate();}}CalendarMesssage类import java.util.Calendar;public class CalendarMessage {int year=-1,month=-1,day=-1;public int getYear(){return year;}public void setMonth(int month){if(month<=12&&month>=1)this.month=month;elsethis.month =1;}public int getMonth(){return month;}public void setDay(int day){this.day =day;}public int getDay(){return day ;}public String []getMonthCalendar(){String[] day=new String[42];Calendar rili =Calendar.getInstance();rili.set(year, month-1,1);int 星期几=rili.get(Calendar.DAY_OF_WEEK )-1;int dayAmount=0;if(month==1||month==3||month==5||month==7||month==8||month==10||month== 12)dayAmount=31;if(month==4||month==6||month==9||month==11)dayAmount=30;if(month==2)if(((year%4==0)&&(year%100!=0)||year%400==0))dayAmount=29;elsedayAmount=28;for(int i=0;i<星期几;i++)day[i]="";for(int i=星期几,n=1;i<星期几+dayAmount;i++){day[i]=String.valueOf(n);n++;}for(int i=星期几+dayAmount;i<42;i++)day[i]="";return day;}public void setYear(int year) {this.year = year;}}NotePad类import java.awt.*;import javax.swing.*;import javax.swing.border.Border;import javax.swing.event.ListSelectionEvent;import javax.swing.event.ListSelectionListener;import java.io.*;import java.awt.event.*;public class NotePad extends JPanel implements ActionListener {JTextArea text;JTextField showMessage;JPopupMenu menu;JMenuItem itemCopy, itemCut, itemPaste, itemClear, btn;public NotePad() {showMessage = new JTextField();showMessage.setHorizontalAlignment(JTextField.CENTER);showMessage.setFont(new Font("TimesRoman", Font.BOLD, 16));showMessage.setForeground(Color.blue);showMessage.setBackground(Color.pink);showMessage.setBorder(BorderFactory.createRaisedBevelBorder());showMessage.setEditable(false);menu = new JPopupMenu();itemCopy = new JMenuItem("复制");itemCut = new JMenuItem("剪切");itemPaste = new JMenuItem("粘贴");itemClear = new JMenuItem("清空");btn = new JMenuItem("字体");itemCopy.addActionListener(this);itemCut.addActionListener(this);itemPaste.addActionListener(this);itemClear.addActionListener(this);btn.addActionListener(this);menu.add(itemCopy);menu.add(itemCut);menu.add(itemPaste);menu.add(itemClear);menu.add(btn);text = new JTextArea(10, 10);text.addMouseListener(new MouseAdapter() {public void mousePressed(MouseEvent e) {if (e.getModifiers() == InputEvent.BUTTON3_MASK)menu.show(text, e.getX(), e.getY());}});setLayout(new BorderLayout());add(showMessage, BorderLayout.NORTH);add(new JScrollPane(text), BorderLayout.CENTER);}public void setShowMessage(int year, int month, int day) {showMessage.setText("" + year + "年" + month + "月" + day + "日");showMessage.setForeground(Color.blue);showMessage.setFont(new Font("宋体", Font.BOLD, 15));}public void save(File dir, int year, int month, int day) {String dailyContent = text.getText();String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = dir.list();boolean boo = false;for (int k = 0; k < dayFile.length; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "" + year + "年" + month + "月" + day+ "已有日志,将新的内容添加到日志吗?";int ok = JOptionPane.showConfirmDialog(this, m, "",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f, "rw");long fileEnd = out.length();byte[] bb = dailyContent.getBytes();out.seek(fileEnd);out.write(bb);out.close();} catch (IOException exp) {}}} else {String m = "" + year + "年" + month + "月" + day + "还没有日志,保存日志吗?";int ok = JOptionPane.showConfirmDialog(this, m, "询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f, "rw");long fileEnd = out.length();byte[] bb = dailyContent.getBytes();out.seek(fileEnd);out.write(bb);out.close();} catch (IOException exp) {}}}}public void delete(File dir, int year, int month, int day) {String key = "" + year + "" + month + "" + day;String[] dayFile = dir.list();boolean boo = false;for (int k = 0; k < dayFile.length; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "删除" + year + "年" + month + "月" + day + "日的日志吗?";int ok = JOptionPane.showConfirmDialog(this, m, "询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if (ok == JOptionPane.YES_OPTION) {String fileName = "" + year + "" + month + "" + day + ".txt";File deleteFile = new File(dir, fileName);deleteFile.delete();}}else {String m = "" + year + "" + month + "" + day + "";JOptionPane.showMessageDialog(this, m, "提示",JOptionPane.WARNING_MESSAGE);}}public void read(File dir, int year, int month, int day) {String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = dir.list();boolean boo = false;for (int k = 0; k < dayFile.length; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {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(null);try {File f = new File(dir, fileName);FileReader inOne = new FileReader(f);BufferedReader inTwo = new BufferedReader(inOne);String s = null;while ((s = inTwo.readLine()) != null)text.append(s + "\n");inOne.close();inTwo.close();} catch (IOException exp) {}}} else {String m = "" + year + "" + month + "" + day + "";JOptionPane.showMessageDialog(this, m, "提示",JOptionPane.WARNING_MESSAGE);}}public void actionPerformed(ActionEvent e) {if (e.getSource() == itemCopy)text.copy();else if (e.getSource() == itemCut)text.cut();else if (e.getSource() == itemPaste)text.paste();else if (e.getSource() == itemClear)text.setText(null);if (e.getSource() == btn) {JFontDialog nFD = new JFontDialog("选择字体");nFD.setModal(true);nFD.setVisible(true);text.setFont(nFD.myFont);}}}class JFontDialog extends JDialog {private static final long serialVersionUID = 1L;JList fontpolics, fontstyle, fontsize;JTextField fontpolict, fontstylet, fontsizet;String example;JLabel FontResolvent;JButton buttonok, buttoncancel;Font myFont;public JFontDialog(String title) {Container container = getContentPane();container.setLayout(new BorderLayout());JPanel panel = new JPanel();panel.setLayout(new GridLayout(2, 1));JPanel FontSet, FontView;FontSet = new JPanel(new GridLayout(1, 4));FontView = new JPanel(new GridLayout(1, 2));example = "AaBbCcDdEe";FontResolvent = new JLabel(example, JLabel.CENTER);FontResolvent.setBackground(Color.WHITE);ListSelectionListener selectionListener = new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) {if (((JList) e.getSource()).getName().equals("polic")) {fontpolict.setText((String) fontpolics.getSelectedValue());FontResolvent.setFont(new Font(fontpolict.getText(),FontResolvent.getFont().getStyle(), FontResolvent.getFont().getSize()));}if (((JList) e.getSource()).getName().equals("style")) {fontstylet.setText((String) fontstyle.getSelectedValue());FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), fontstyle.getSelectedIndex(),FontResolvent.getFont().getSize()));}if (((JList) e.getSource()).getName().equals("size")) {fontsizet.setText((String) fontsize.getSelectedValue());try {Integer.parseInt(fontsizet.getText());} catch (Exception excepInt) {fontsizet.setText(FontResolvent.getFont().getSize()+ "");}FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), FontResolvent.getFont().getStyle(),Integer.parseInt(fontsizet.getText())));}}};KeyListener keyListener = new KeyListener() {public void keyPressed(KeyEvent e) {if (e.getKeyCode() == 10) {if (((JTextField) e.getSource()).getName().equals("polic")) {FontResolvent.setFont(new Font(fontpolict.getText(),FontResolvent.getFont().getStyle(),FontResolvent.getFont().getSize()));}if (((JTextField) e.getSource()).getName().equals("style")) {fontstylet.setText((String) fontstyle.getSelectedValue());FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), fontstyle.getSelectedIndex(),FontResolvent.getFont().getSize()));}if (((JTextField) e.getSource()).getName().equals("size")) {try {Integer.parseInt(fontsizet.getText());} catch (Exception excepInt) {fontsizet.setText(FontResolvent.getFont().getSize()+ "");}FontResolvent.setFont(new Font(FontResolvent.getFont().getFontName(), FontResolvent.getFont().getStyle(), Integer.parseInt(fontsizet.getText())));}}}public void keyReleased(KeyEvent e) {}public void keyTyped(KeyEvent e) {}};// 字体JPanel Fontpolic = new JPanel();Border border = BorderFactory.createLoweredBevelBorder();border = BorderFactory.createTitledBorder(border, "字体");Fontpolic.setBorder(border);Font[] fonts = java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();int taille = fonts.length;String[] policnames = new String[taille];for (int i = 0; i < taille; i++) {policnames[i] = fonts[i].getName();}fontpolics = new JList(policnames);fontpolics.setName("polic");fontpolics.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontpolics.addListSelectionListener(selectionListener);fontpolics.setVisibleRowCount(6);fontpolict = new JTextField(policnames[0]);fontpolict.setName("polic");fontpolict.addKeyListener(keyListener);JScrollPane jspfontpolic = new JScrollPane(fontpolics);Fontpolic.setLayout(new BoxLayout(Fontpolic, BoxLayout.PAGE_AXIS)); Fontpolic.add(fontpolict);Fontpolic.add(jspfontpolic);// 样式JPanel Fontstyle = new JPanel();border = BorderFactory.createLoweredBevelBorder();border = BorderFactory.createTitledBorder(border, "样式");Fontstyle.setBorder(border);String[] styles = { "PLAIN", "BOLD", "ITALIC", "BOLD ITALIC" };fontstyle = new JList(styles);fontstyle.setName("style");fontstyle.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontstyle.addListSelectionListener(selectionListener);fontstyle.setVisibleRowCount(6);fontstylet = new JTextField(styles[0]);fontstylet.setName("style");fontstylet.addKeyListener(keyListener);JScrollPane jspfontstyle = new JScrollPane(fontstyle);Fontstyle.setLayout(new BoxLayout(Fontstyle, BoxLayout.PAGE_AXIS)); Fontstyle.add(fontstylet);Fontstyle.add(jspfontstyle);// 大小JPanel Fontsize = new JPanel();border = BorderFactory.createLoweredBevelBorder();border = BorderFactory.createTitledBorder(border, "大小");Fontsize.setBorder(border);String[] sizes = { "10", "14", "18", "22", "26", "30" };fontsize = new JList(sizes);fontsize.setName("size");fontsize.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); fontsize.addListSelectionListener(selectionListener);fontsize.setVisibleRowCount(6);fontsizet = new JTextField(sizes[0]);fontsizet.setName("size");fontsizet.addKeyListener(keyListener);JScrollPane jspfontsize = new JScrollPane(fontsize);Fontsize.setLayout(new BoxLayout(Fontsize, BoxLayout.PAGE_AXIS)); Fontsize.add(fontsizet);Fontsize.add(jspfontsize);FontSet.add(Fontpolic);FontSet.add(Fontstyle);FontSet.add(Fontsize);FontView.add(FontResolvent);panel.add(FontSet);panel.add(FontView);JPanel panelnorth = new JPanel();panelnorth.setLayout(new FlowLayout());buttonok = new JButton("确定");buttoncancel = new JButton("取消");panelnorth.add(buttonok);panelnorth.add(buttoncancel);buttonok.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {myFont = FontResolvent.getFont();JFontDialog.this.setVisible(false);}});buttoncancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {JFontDialog.this.setVisible(false);}});container.add(panel, BorderLayout.CENTER);container.add(panelnorth, BorderLayout.SOUTH);setSize(400, 300);}}CalendarImage类import javax.swing.*;import java.io.*;import java.awt.*;public class CalendarImage extends JPanel{File imageFile;Image image;Toolkit tool;CalendarImage(){tool=getToolkit();}public void setImageFile(File f){imageFile=f;try{ image=tool.getImage(imageFile.toURI().toURL());}catch(Exception exp){}repaint();}public void paintComponent(Graphics g){super.paintComponent(g);int w=getBounds().width;int h=getBounds().height;g.drawImage(image, 0, 0, w, h, this);}}Clock类import java.applet.Applet;import java.applet.AudioClip;import java.awt.BasicStroke;import java.awt.Color;import java.awt.Graphics;import java.awt.Graphics2D;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.geom.Line2D;import java.io.File;import .MalformedURLException;import .URI;import .URL;import java.util.Date;import javax.swing.JPanel;public class Clock extends JPanel implements ActionListener { Date date;javax.swing.Timer secondTime;int hour,munite,second;Line2D secondLine,muniteLine,hourLine;Line2D m=new Line2D.Double(0,0,0,0);Line2D s=new Line2D.Double(0,0,0,0);int a,b,c,width,height;double pointSX[]=new double[60],pointSY[]=new double[60],pointMX[]=new double[60],pointMY[]=new double[60],pointHX[]=new double[60],pointHY[]=new double[60];Clock(){setBackground(Color.cyan);initPoint();secondTime=new javax.swing.Timer(1000,this);secondLine=new Line2D.Double(0,0,0,0);muniteLine=new Line2D.Double(0,0,0,0);hourLine=new Line2D.Double(0,0,0,0);secondTime.start();}private void initPoint(){width=getBounds().width;height=getBounds().height;pointSX[0]=0;pointSY[0]=-height/2*5/6;pointMX[0]=0;pointMY[0]=-(height/2*4/5);pointHX[0]=0;pointHY[0]=-(height/2*2/3);double angle=6*Math.PI/180;for(int i=0;i<59;i++){pointSX[i+1]=pointSX[i]*Math.cos(angle)-Math.sin(angle)*pointSY[i];pointSY[i+1]=pointSY[i]*Math.cos(angle)+pointSX[i]*Math.sin(angle);pointMX[i+1]=pointMX[i]*Math.cos(angle)-Math.sin(angle)*pointMY[i];pointMY[i+1]=pointMY[i]*Math.cos(angle)+pointMX[i]*Math.sin(angle);pointHX[i+1]=pointHX[i]*Math.cos(angle)-Math.sin(angle)*pointHY[i];pointHY[i+1]=pointHY[i]*Math.cos(angle)+pointHX[i]*Math.sin(angle);}for(int i=0;i<60;i++){pointSX[i]=pointSX[i]+width/2;pointSY[i]=pointSY[i]+height/2;pointMX[i]=pointMX[i]+width/2;pointMY[i]=pointMY[i]+height/2;pointHX[i]=pointHX[i]+width/2; pointHY[i]=pointHY[i]+height/2;}}public void paintComponent(Graphics g){super.paintComponent(g);initPoint();for(int i=0;i<60;i++){int m=(int)pointSX[i];int n=(int)pointSY[i];if(i%5==0){if(i==0||i==15||i==30||i==45){int k=10;g.setColor(Color.orange);g.fillOval(m-k/2, n-k/2, k, k);}else{int k=7;g.setColor(Color.orange );g.fillOval(m-k/2, n-k/2, k, k);}}else{int k=2;g.setColor(Color.black);g.fillOval(m-k/2, n-k/2, k, k);}}g.fillOval(width/2-5, height/2-5, 10, 10);Graphics2D g_2d=(Graphics2D)g;g_2d.setColor(Color.red);g_2d.draw(secondLine);BasicStroke bs=newBasicStroke(2f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_MITER);g_2d.setStroke(bs);g_2d.setColor(Color.blue);g_2d.draw(muniteLine);bs=newBasicStroke(2f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER);g_2d.setStroke(bs);g_2d.setColor(Color.orange);g_2d.draw(hourLine);bs=newBasicStroke(4f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER);g_2d.setStroke( bs);}public void actionPerformed(ActionEvent e){if(e.getSource()==secondTime){date=new Date();String s=date.toString();。
东华理工大学信息工程学院《JAVA技术应用开发》课程设计报告日历记事本******学号:************同组成员:无完成日期:2015.7.3目录1.项目概述 (2)2.需求分析 (2)3.概要设计 (3)3.1功能结构 (3)3.2布局 (3)4.详细设计及功能实现 (4)4.1结构 (4)4.2主界面 (5)4.3日历模块 (8)4.4记事本模块 (9)4.5记事列表模块 (12)4.6提醒功能 (13)5.运行测试 (15)6.总结 (19)1.项目概述日历记事本是将日历和记事本结合在一起,用户可以任意选择某一天,保存这一天需要记录的记事,或者任意查看某一天已经记录的记事。
同时还应具备提醒功能,当到达提醒时间时会自动弹出提醒。
2.需求分析日历记事本大致分为日历和记事两个部分。
①日历部分首先,需要选择日期,用户可以通过点击按钮选择前一年或后一年,同样也可以选择前一个月或后一个月,当月份为1月时,用户点击前一个月,会自动跳转到前一年的12月,同理,在12月时点击后一个月,会自动跳转到下一年的1月。
另外,当选择跨度比较大时,需要多次点击按钮,很不方便,所以需要一个下拉框,可以直接选择某一年或某一个月。
当用户改变选择日期时,日历会自动显示出这一个月的日历,并且可以通过点击某一天,来进行添加记事的操作,鼠标经过日历或点击日历时,会有不同的效果以提示用户这是可以点击的。
②记事部分首先,需要一个文本域给用户编辑记事内容,记事和日历部分所选择的日期是相关的,当用户点击日历选择某一天,则记事本上端会显示出选择的日期信息。
同时,记事应该还具有设置提醒的功能,用户点击设置提醒按钮后,会弹出一个新的对话框,用来选择提醒时间。
为保存记事,应将记事以文件的形式存储在计算机上。
另外,当用户想查看所有记事,或者想搜索某一则记事时,可以将日历部分换成一个表格,列出所有的记事,或者符合搜索结果的记事。
3.概要设计3.1功能结构日历记事本以功能划分,大致分为日历、记事列表及记事本三个部分:3.2布局软件界面的大致布局如下图,可以通过点击按钮将日历切换为记事列表4.详细设计及功能实现4.1结构①类结构②文件存储结构程序第一次运行时,会在设定的位置自动创建路径:“.../日历记事本/data/”。
Java日历记事本课程设计报告在设计日历记事本时,需要编写6个JAVA源文件:、、、、和效果图如下. CalendarWindow类import .*;import .*;import .*;import .*;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= ;public CalendarWindow(){dir=new File("./dailyRecord");();showDay=new JTextField[42];for(int i=0;i<;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=();(new Date());year=;month=+1;day=;(year);(month);(day);(calendarMessage);(showDay);(year,month,day);();doMark();calendarImage=new CalendarImage();(new File(""));clock=new Clock();JSplitPane splitV1=new JSplitPane,calendarPad,calendarImage);JSplitPane splitV2=new JSplitPane,notePad,clock);JSplitPane splitH=new JSplitPane,splitV1,splitV2);add(splitH,;showYear=new JTextField(""+year,6);(new Font("TimesRoman",,12));;showMonth=new JTextField(""+month,4);(new Font("TimesRoman",,12));;nextYear=new JButton("下年");previousYear=new JButton("上年");nextMonth=new JButton("下月");previousMonth=new JButton("上月");(this);(this);(this);(this);JPanel north=new JPanel();(previousYear);(showYear);(nextYear);(previousMonth);(showMonth);(nextMonth);add(north,;saveDailyRecord=new JButton("保存日志");deleteDailyRecord=new JButton("删除日志");readDailyRecord=new JButton("读取日志");(this);(this);(this);JPanel pSouth=new JPanel();(saveDailyRecord);(deleteDailyRecord);(readDailyRecord);add(pSouth,;getPicture=new JButton("选择日历图像");(this);(getPicture);add(pSouth,;setVisible(true);setBounds(60,60,660,480);validate();setDefaultCloseOperation;}public void actionPerformed(ActionEvent e){ if()==nextYear){year++;(""+year);(year);(calendarMessage);();(year,month,day);doMark();}else if()==previousYear){year--;(""+year);(year);(calendarMessage);();(year,month,day);doMark();}else if()==nextMonth){month++;if(month<1) month=12;(""+month);(month);(calendarMessage);();(year,month,day);doMark();}else if()==previousMonth){month--;if(month<1) month=12;(""+month);(month);(calendarMessage);();(year,month,day);doMark();}else if()==showYear){String s=().trim();char a[]=();boolean boo=false;for(int i=0;i<;i++)if(!(a[i])))boo=true;if(boo==true)(this, "您输入了非法年份","警告",;else if(boo==false)year=(s);(""+year);(year);(calendarMessage);();(year,month,day);doMark();}else if()==saveDailyRecord){(dir,year,month,day);doMark();}else if()==deleteDailyRecord){(dir,year,month,day);doMark();}else if()==readDailyRecord){(dir,year,month,day);}else if () ==getPicture ) {FileDialog fd=new FileDialog(this,"打开文件对话框");(true);String fileopen = null, filename = null;fileopen = ();filename = ();(new File(fileopen,filename));}}public void mousePressed(MouseEvent e){JTextField text=(JTextField)();String str=().trim();try{ day=(str);}catch(NumberFormatException exp){}(day);(year,month,day);}public void mouseReleased(MouseEvent e){} public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}public void mouseClicked(MouseEvent e){}public void focusGained(FocusEvent e){Component com=(Component)();;}public void focusLost(FocusEvent e){Component com=(Component)();(backColor);}public void doMark(){for(int i=0;i<;i++){showDay[i].removeAll();String str=showDay[i].getText().trim();try{int n=(str);if(isHaveDailyRecord(n)==true){JLabel mess=new JLabel("有");(new Font("TimesRoman",,11));;showDay[i].add(mess);}}catch(Exception exp){}}();();}public boolean isHaveDailyRecord(int n){ String key=""+year+""+month+""+n;String [] dayFile=();boolean boo=false;for(int k=0;k<;k++){if(dayFile[k].equals(key+".txt")){boo=true;break;}}return boo;}public String getPicture_address() {String address = null;try {InputStream outOne = new FileInputStream("");ObjectInputStream outTwo = new ObjectInputStream(outOne);try {address = (String) ();} catch (Exception ex) {}();} catch (IOException eee) {}if (address != null) {return address;} else {return "";}}public void actionPerformed1(ActionEvent e) {if ().equals("更改图片背景")) {FileDialog dia = new FileDialog(this, "选择图片", ;(true);(true);if (() != null) && () != null)) {try {FileOutputStream inOne = new FileOutputStream("");ObjectOutputStream inTwo = new ObjectOutputStream(inOne);() + ());();} catch (IOException ee) {}String picturename = getPicture_address();(new File(picturename));}}}public static void main(String args[]){new CalendarWindow();}}CalendarPad类import .*;import .*;import .*;import class CalendarPad extends JPanel{int year,month,day;CalendarMessage calendarMessage;JTextField[] showDay;JLabel title[];String[] 星期={"SUN 日","MON 一","TUE 二","WED 三","THU 四","FRI 四","SAT 六"};JPanel north,center;public CalendarPad(){setLayout(new BorderLayout());north=new JPanel();(new GridLayout(1,7));center=new JPanel();(new GridLayout(6,7));add(center , );add(north, );title=new JLabel[7];for(int j=0;j<7;j++){title[j]=new JLabel();title[j].setFont(new Font("TimesRoman", ,12));title[j].setText(星期[j]);title[j].setHorizontalAlignment;title[j].setBorder());(title[j]);}title[0].setForeground;title[6].setForeground;}public void setShowDayTextField(JTextField[]text){showDay=text;for(int i=0;i<;i++){showDay[i].setFont(new Font("TimesRoman", ,15));showDay[i].setHorizontalAlignment;showDay[i].setEditable(false);(showDay[i]);}}public void setCalendarMessage (CalendarMessage calendarMessage){=calendarMessage;}public void showMonthCalendar(){String[] a=();for(int i=0;i<42;i++)showDay[i].setText(a[i]);validate();}}CalendarMesssage类import class CalendarMessage {int year=-1,month=-1,day=-1;public int getYear(){return year;}public void setMonth(int month){if(month<=12&&month>=1)=month;else=1;}public int getMonth(){return month;}public void setDay(int day){=day;}public int getDay(){return day ;}public String []getMonthCalendar(){String[] day=new String[42];Calendar rili =();(year, month-1,1);int 星期几= )-1;int dayAmount=0;if(month==1||month==3||month==5||month==7||month==8||month==10 ||month==12)dayAmount=31;if(month==4||month==6||month==9||month==11)dayAmount=30;if(month==2)if(((year%4==0)&&(year%100!=0)||year%400==0))dayAmount=29;elsedayAmount=28;for(int i=0;i<星期几;i++)day[i]="";for(int i=星期几,n=1;i<星期几+dayAmount;i++){day[i]=(n);n++;}for(int i=星期几+dayAmount;i<42;i++)day[i]="";return day;}public void setYear(int year) {= year;}}NotePad类import .*;import .*;import .*;import class NotePad extends JPanel implements ActionListener { JTextArea text;JTextField showMessage;JPopupMenu menu;JMenuItem itemCopy, itemCut, itemPaste, itemClear, btn;public NotePad() {showMessage = new JTextField();;(new Font("TimesRoman", , 16));;;());(false);menu = new JPopupMenu();itemCopy = new JMenuItem("复制");itemCut = new JMenuItem("剪切");itemPaste = new JMenuItem("粘贴");itemClear = new JMenuItem("清空");btn = new JMenuItem("字体");(this);(this);(this);(this);(this);(itemCopy);(itemCut);(itemPaste);(itemClear);(btn);text = new JTextArea(10, 10);(new MouseAdapter() {public void mousePressed(MouseEvent e) {if () ==(text, (), ());}});setLayout(new BorderLayout());add(showMessage, ;add(new JScrollPane(text), ;}public void setShowMessage(int year, int month, int day) { ("" + year + "年" + month + "月" + day + "日");;(new Font("宋体", , 15));}public void save(File dir, int year, int month, int day) {String dailyContent = ();String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = ();boolean boo = false;for (int k = 0; k < ; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "" + year + "年" + month + "月" + day+ "已有日志,将新的内容添加到日志吗";int ok = (this, m, "",, ;if (ok == {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f, "rw");long fileEnd = ();byte[] bb = ();(fileEnd);(bb);();} catch (IOException exp) {}}} else {String m = "" + year + "年" + month + "月" + day + "还没有日志,保存日志吗";int ok = (this, m, "询问",, ;if (ok == {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f, "rw");long fileEnd = ();byte[] bb = ();(fileEnd);(bb);();} catch (IOException exp) {}}}}public void delete(File dir, int year, int month, int day) { String key = "" + year + "" + month + "" + day;String[] dayFile = ();boolean boo = false;for (int k = 0; k < ; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "删除" + year + "年" + month + "月" + day + "日的日志吗";int ok = (this, m, "询问",, ;if (ok == {String fileName = "" + year + "" + month + "" + day + ".txt";File deleteFile = new File(dir, fileName);();}}else {String m = "" + year + "" + month + "" + day + "";(this, m, "提示",;}}public void read(File dir, int year, int month, int day) { String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = ();boolean boo = false;for (int k = 0; k < ; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}}if (boo) {String m = "" + year + "" + month + "" + day + "";int ok = (this, m, "询问",, ;if (ok == {(null);try {File f = new File(dir, fileName);FileReader inOne = new FileReader(f);BufferedReader inTwo = new BufferedReader(inOne);String s = null;while ((s = ()) != null)(s + "\n");();();} catch (IOException exp) {}}} else {String m = "" + year + "" + month + "" + day + "";(this, m, "提示",;}}public void actionPerformed(ActionEvent e) {if () == itemCopy)();else if () == itemCut)();else if () == itemPaste)();else if () == itemClear)(null);if () == btn) {JFontDialog nFD = new JFontDialog("选择字体");(true);(true);;}}}class JFontDialog extends JDialog {private static final long serialVersionUID = 1L;JList fontpolics, fontstyle, fontsize;JTextField fontpolict, fontstylet, fontsizet;String example;JLabel FontResolvent;JButton buttonok, buttoncancel;Font myFont;public JFontDialog(String title) {Container container = getContentPane();(new BorderLayout());JPanel panel = new JPanel();(new GridLayout(2, 1));JPanel FontSet, FontView;FontSet = new JPanel(new GridLayout(1, 4));FontView = new JPanel(new GridLayout(1, 2));example = "AaBbCcDdEe";FontResolvent = new JLabel(example, ;;ListSelectionListener selectionListener = new ListSelectionListener() {public void valueChanged(ListSelectionEvent e) {if (((JList) ()).getName().equals("polic")) {((String) ());(new Font(),().getStyle(), FontResolvent.getFont().getSize()));}if (((JList) ()).getName().equals("style")) {((String) ());(new Font().getFontName(), (),().getSize()));}if (((JList) ()).getName().equals("size")) {((String) ());try {());} catch (Exception excepInt) {().getSize()+ "");}(new Font().getFontName(), ().getStyle(),())));}}};KeyListener keyListener = new KeyListener() {public void keyPressed(KeyEvent e) {if () == 10) {if (((JTextField) ()).getName().equals("polic")) {(new Font(),().getStyle(),().getSize()));}if (((JTextField) ()).getName().equals("style")) {((String) fontstyle.getSelectedValue());(new Font().getFontName(), (),().getSize()));}if (((JTextField) ()).getName().equals("size")) {try {());} catch (Exception excepInt) {().getSize()+ "");}(new Font().getFontName(), ().getStyle(), (fontsizet.getText())));}}}public void keyReleased(KeyEvent e) {}public void keyTyped(KeyEvent e) {}};etLocalGraphicsEnvironment().getAllFonts();int taille = ;String[] policnames = new String[taille];for (int i = 0; i < taille; i++) {policnames[i] = fonts[i].getName();}fontpolics = new JList(policnames);("polic");;(selectionListener);(6);fontpolict = new JTextField(policnames[0]);("polic");(keyListener);JScrollPane jspfontpolic = new JScrollPane(fontpolics);(new BoxLayout(Fontpolic, );(fontpolict);(jspfontpolic);;import .*;import .*;public class CalendarImage extends JPanel{File imageFile;Image image;Toolkit tool;CalendarImage(){tool=getToolkit();}public void setImageFile(File f){imageFile=f;try{ image=().toURL());}catch(Exception exp){}repaint();}public void paintComponent(Graphics g){(g);int w=getBounds().width;int h=getBounds().height;(image, 0, 0, w, h, this);}}Clock类import class Clock extends JPanel implements ActionListener {Date date;secondTime;int hour,munite,second;Line2D secondLine,muniteLine,hourLine;Line2D m=new (0,0,0,0);Line2D s=new (0,0,0,0);int a,b,c,width,height;double pointSX[]=new double[60],pointSY[]=new double[60],pointMX[]=new double[60],pointMY[]=new double[60],pointHX[]=new double[60],pointHY[]=new double[60];Clock(){setBackground;initPoint();secondTime=new secondLine=new (0,0,0,0);muniteLine=new (0,0,0,0);hourLine=new (0,0,0,0);();}private void initPoint(){width=getBounds().width;height=getBounds().height;pointSX[0]=0;pointSY[0]=-height/2*5/6;pointMX[0]=0;pointMY[0]=-(height/2*4/5);pointHX[0]=0;pointHY[0]=-(height/2*2/3);double angle=6*180;for(int i=0;i<59;i++){pointSX[i+1]=pointSX[i]*(angle)(angle)*pointSY[i];pointSY[i+1]=pointSY[i]*(angle)+pointSX[i]*(angle);pointMX[i+1]=pointMX[i]*(angle)(angle)*pointMY[i];pointMY[i+1]=pointMY[i]*(angle)+pointMX[i]*(angle);pointHX[i+1]=pointHX[i]*(angle)(angle)*pointHY[i];pointHY[i+1]=pointHY[i]*(angle)+pointHX[i]*(angle);}for(int i=0;i<60;i++){pointSX[i]=pointSX[i]+width/2;pointSY[i]=pointSY[i]+height/2;pointMX[i]=pointMX[i]+width/2;pointMY[i]=pointMY[i]+height/2;pointHX[i]=pointHX[i]+width/2; pointHY[i]=pointHY[i]+height/2;}}public void paintComponent(Graphics g){(g);initPoint();for(int i=0;i<60;i++){int m=(int)pointSX[i];int n=(int)pointSY[i];if(i%5==0){if(i==0||i==15||i==30||i==45){int k=10;;(m-k/2, n-k/2, k, k);}else{int k=7;);(m-k/2, n-k/2, k, k);}}else{int k=2;;(m-k/2, n-k/2, k, k);}}(width/2-5, height/2-5, 10, 10);Graphics2D g_2d=(Graphics2D)g;;(secondLine);BasicStroke bs=new BasicStroke(2f,,;(bs);;(muniteLine);bs=new BasicStroke(2f,,;(bs);;(hourLine);bs=new BasicStroke(4f,,;(bs);}public void actionPerformed(ActionEvent e){if()==secondTime){date=new Date();String s=();hour=(11, 13));munite=(14, 16));second=(17, 19));int h=hour%12;a=second;b=munite;c=h*5+munite/12;(width/2,height/2,(int)pointSX[a],(int)pointSY[a]);(width/2,height/2,(int)pointMX[b],(int)pointMY[b]);(width/2,height/2,(int)pointHX[c],(int)pointHY[c]);repaint();if ((munite==0)&&(second==0)){try{File f=new File("");URI uri=();URL url=();AudioClip aau;aau=(url);();}catch(MalformedURLException ex){();}}}}}21。
Java语言与面向对象技术课程设计报告( 2013 -- 2014年度第1 学期)日历记事本专业软件工程学生姓名班级学号指导教师完成日期目录1 概述 (1)1.1 课程设计目的 (1)1.2 课程设计内容 (1)2 系统需求分析 (1)2.1 系统目标 (1)2.2 主体功能 (1)2.3 开发环境 (1)3 系统概要设计 (1)3.1 系统的功能模块划分 (1)3.2 系统流程图 (2)4系统详细设计 (2)5 测试 (5)5.1 测试方案 (11)5.2 测试结果 (12)6 小结 (14)参考文献 (15)附录 (16)附录1 源程序清单 (16)日历记事本1 概述1.1 课程设计目的1.学习Java程序开发的环境搭建与配置,并且在实际运用中学习和和掌握Java 程序开发的过程2.通过课程设计进一步掌握Java程序设计语言的基础内容,如用户图形界面设计等3.通过亲自设计,编写,调试程序来扩展知识面和动手操作能力4.加强研发、调试程序的能力;增强分析、解决问题的能力;提高科技论文写作能力1.2 课程设计内容设计GUI界面的日历记事本。
系统将日历、记事本功能结合在一起,用户可以方便地在任何日期记录下有关内容或查看某个日期的记录内容。
2 系统需求分析2.1 系统目标1.系统界面的左侧是日历。
该日历可以按年份前后翻动,鼠标单击“上年”按钮时,当前的日历的年份减一;当鼠标左键单击“下年”按钮,当前日历年份加一。
2.该日历也可以在某年内按月前后翻动,鼠标单击“上月”按钮时,当前的日历的月份减一;当鼠标左键单击“下月”按钮,当前日历月份加一。
3.使用鼠标左键单击选定的日期,如已有记录内容,系统将弹出对话框提示该日已有记录内容,并询问用户是否用记事本显示该内容。
2.2 主体功能1.用户可以方便地在任何日期记录下有关内容或查看某个日期的记录内容。
2.通过按按钮“上年”和“下年”对年份进行翻页;通过按按钮“上月”和“下月”对月份进行翻页。
题目:日历记事本一、实验内容用所学的Java知识,设计出日历记事本程序。
(其中:保存、读取和删除过程)二、需求分析◆建立日历记事本界面,其中包括时钟、日历和记事大部分操作、显示、清除◆所编写的程序可以正常运算;◆所编写的程序可以正确记事;三、实验目的★ 1、加深对Java语言的了解,增强Java的编写能力;★ 2、巩固专业知识,Java复习语言的类及其他基础内容;★ 3、增强学生的动手实践能力,开拓学生的视野;★ 4、丰富学生的想象力及独立思考能力。
四、组员及分工廖俊军:CalendarMessage、CalendarPad、NotePad刘伟才:CalendarWindow伍星:Clock五、系统总体设计:主要功能模块的算法设计思路如下:1、主类(CalendarWindow.java)主要功能介绍:(1)运行的标志;(2)调用包中的各种类。
(3)界面代码及主函数的书写(4)窗口的排版及按钮的位置摆放(5)实现各按钮和标签的创建和功能2、数据类(CalendarMessage.java)主要功能介绍:用来刻画和“日期”有关的数据。
3、数据显示和修改类(CalendarPad.java)主要功能介绍:用来表示“日历”,即负责显示和修改CalendarMessage对象中的日期数据。
4、记事本类(NotePad.java)主要功能介绍:创建以提供编辑、读取、保存和删除日志的功能。
5、时钟类(Clock.java)主要功能介绍:负责显示时钟。
6、图像类(CalendarImage.java)主要功能介绍:负责绘制图像。
六、程序详细设计:代码如下:1、主类(CalendarWindow.java)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;Clock clock;JButton nextYear,previousYear,nextMonth,previousMonth;JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;File dir;Color backColor=Color.white;public CalendarWindow(){dir=new File("./dailyRecord");dir.mkdir();showDay=new JTextField[42];for(int i=0;i<showDay.length;i++){showDay[i]=new JTextField();showDay[i].setBackground(backColor);showDay[i].setLayout(new GridLayout(3,3));showDay[i].addMouseListener(this);showDay[i].addActionListener(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(); //给有日志的号码做标记,见后面的doMark()方法calendarImage=new CalendarImage();calendarImage.setImageFile(new File("flower.jpg"));clock=new Clock();JSplitPane splitV1=newJSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarImage); JSplitPane splitV2=new JSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,clock); JSplitPane splitH=newJSplitPane(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);showYear.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);setVisible(true);setBounds(60,60,660,480);validate();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e){ //鼠标获取按钮内容的动作函数if(e.getSource()==nextYear){ //“下一年”year++;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousYear){ //“上一年”year--;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==nextMonth){ //“下一月”month++;if(month>12) month=1;showMonth.setText(" "+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousMonth){ //、“上一月”month--;if(month<1) month=12;showMonth.setText(" "+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==showYear){String s=showYear.getText().trim();char a[]=s.toCharArray();boolean boo=false;for(int i=0;i<a.length;i++)if(!(Character.isDigit(a[i])))boo=true;if(boo==true) //弹出“警告”消息对话框JOptionPane.showMessageDialog(this,"您输入了非法年份","警告",JOptionPane.WARNING_MESSAGE);else if(boo==false)year=Integer.parseInt(s);showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==saveDailyRecord){ //“保存日记”notePad.save(dir,year,month,day);doMark();}else if(e.getSource()==deleteDailyRecord){ //“删除日记”notePad.delete(dir,year,month,day);doMark();}else if(e.getSource()==readDailyRecord) //“读取日记”notePad.read(dir,year,month,day);}public void mousePressed(MouseEvent e){JTextField text=(JTextField)e.getSource();String str=text.getText().trim();try{ day=Integer.parseInt(str);}catch(NumberFormatException exp){}calendarMessage.setDay(day);notePad.setShowMessage(year,month,day);}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mouseClicked(MouseEvent e) {}public void focusGained(FocusEvent e){Component com=(Component)e.getSource();com.setBackground(Color.pink);}public void focusLost(FocusEvent e){ //此事件指示Component 不再是焦点所有者。
日历记事本实验报告题目:日历记事本一、实验内容用所学的Java知识,设计出日历记事本程序。
(其中:保存、读取和删除过程)二、需求分析◆建立日历记事本界面,其中包括时钟、日历和记事大部分操作、显示、清除◆所编写的程序可以正常运算;◆所编写的程序可以正确记事;三、实验目的★ 1、加深对Java语言的了解,增强Java的编写能力;★ 2、巩固专业知识,Java复习语言的类及其他基础内容;★ 3、增强学生的动手实践能力,开拓学生的视野;★ 4、丰富学生的想象力及独立思考能力。
四、组员及分工廖俊军:CalendarMessage、CalendarPad、NotePad刘伟才:CalendarWindow伍星:Clock五、系统总体设计:主要功能模块的算法设计思路如下:1、主类(CalendarWindow.java)主要功能介绍:(1)运行的标志;(2)调用包中的各种类。
(3)界面代码及主函数的书写(4)窗口的排版及按钮的位置摆放(5)实现各按钮和标签的创建和功能2、数据类(CalendarMessage.java)主要功能介绍:用来刻画和“日期”有关的数据。
3、数据显示和修改类(CalendarPad.java)主要功能介绍:用来表示“日历”,即负责显示和修改CalendarMessage对象中的日期数据。
4、记事本类(NotePad.java)主要功能介绍:创建以提供编辑、读取、保存和删除日志的功能。
5、时钟类(Clock.java)主要功能介绍:负责显示时钟。
6、图像类(CalendarImage.java)主要功能介绍:负责绘制图像。
六、程序详细设计:代码如下:1、主类(CalendarWindow.java)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;Clock clock;JButton nextYear,previousYear,nextMonth,previousMonth;JButton saveDailyRecord,deleteDailyRecord,readDailyRecord;File dir;Color backColor=Color.white;public CalendarWindow(){dir=new File("./dailyRecord");dir.mkdir();showDay=new JTextField[42];for(int i=0;i<showday.length;i++){< bdsfid="130" p=""></showday.length;i++){<>showDay[i]=new JTextField();showDay[i].setBackground(backColor);showDay[i].setLayout(new GridLayout(3,3));showDay[i].addMouseListener(this);showDay[i].addActionListener(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(); //给有日志的号码做标记,见后面的doMark()方法calendarImage=new CalendarImage();calendarImage.setImageFile(new File("flower.jpg"));clock=new Clock();JSplitPane splitV1=newJSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarI mage); JSplitPane splitV2=new JSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,clock); JSplitPane splitH=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,splitV1,splitV2);add(splitH,BorderLayout.CENTER);showYear=new JTextField(""+year,6);showYear.setFont(new Font("TimesRoman",Font.BOLD,12));showYear.setHorizontalAlignment(JT extField.CENTER);showMonth=new JTextField(" "+month,4);showMonth.setFont(newFont("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);showYear.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);setVisible(true);setBounds(60,60,660,480);validate();setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}public void actionPerformed(ActionEvent e){ //鼠标获取按钮内容的动作函数if(e.getSource()==nextYear){ //“下一年”year++;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage); calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousYear){ //“上一年”year--;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage); calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==nextMonth){ //“下一月”month++;if(month>12) month=1;showMonth.setT ext(" "+month); calendarMessage.setMonth(month); calendarPad.setCalendarMessage(calendarMessage); calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==previousMonth){ //、“上一月”month--;if(month<1) month=12;showMonth.setT ext(" "+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==showYear){String s=showYear.getText().trim();char a[]=s.toCharArray();boolean boo=false;for(int i=0;i<a.length;i++)< bdsfid="246" p=""></a.length;i++)<>if(!(Character.isDigit(a[i])))boo=true;if(boo==true) //弹出“警告”消息对话框JOptionPane.showMessageDialog(this,"您输入了非法年份","警告",JOptionPane.WARNING_MESSAGE);else if(boo==false)year=Integer.parseInt(s);showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}else if(e.getSource()==saveDailyRecord){ //“保存日记”notePad.save(dir,year,month,day);doMark();}else if(e.getSource()==deleteDailyRecord){ //“删除日记”notePad.delete(dir,year,month,day);doMark();}else if(e.getSource()==readDailyRecord) //“读取日记”notePad.read(dir,year,month,day);}public void mousePressed(MouseEvent e){JTextField text=(JTextField)e.getSource();String str=text.getText().trim();try{ day=Integer.parseInt(str);}catch(NumberFormatException exp){}calendarMessage.setDay(day);notePad.setShowMessage(year,month,day);}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mouseClicked(MouseEvent e) {}public void focusGained(FocusEvent e){Component com=(Component)e.getSource();com.setBackground(Color.pink);}public void focusLost(FocusEvent e){ //此事件指示Component 不再是焦点所有者。
用JAVA编写的一个简单记事本程序用JAVA编写的一个简单记事本程序2019-12-30 14:27/////////////---[Notepad]---\\\\\\import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.*;import java.util.*;import java.io.*;public class Notepad extends JFrame implements ActionListener File file=null;Color color=Color.black;JTextPane text=new JTextPane();//the text area JDialogabout=new JDialog(this);//the dialog of"About"JFileChooser filechooser=new JFileChooser();//file choose GraphicsEnvironmentgetFont=GraphicsEnvironment.getLocalGraphicsEnvironment();Font fonts=getFont.getAllFonts();JColorChooser colorchooser=new JColorChooser();///Menu item for carte///for"File"private JMenuItem jminew,jmiopen,jmisave,jmisaveas;//for"Edit"private JMenuItem jmicut,jmicopy,jmiplaster,jmiall;//for"Format"private JMenuItem jmifont,jmicolor;//for"Tool"private JMenuItem jminotepad,jmicalculator;//for"Help"private JMenuItem jmiabout;//for"Exit"private JMenuItem jmiexit;public static void main(String args)Notepad frame=new Notepad();frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.pack();/////pack():set the size of frame automatic frame.setVisible(true);///Default Constructor public Notepad()setTitle("Notepad");setLocation(100,50);//create menu bar JMenuBar jmb=new JMenuBar();//set menu bar to the frame setJMenuBar(jmb);//add menu"File"to menu bar JMenu filemenu=new JMenu("File");filemenu.setMnemonic('F');//set hotkey jmb.add(filemenu);//add menu"Edit"to menu bar JMenu editmenu=new JMenu("Edit");editmenu.setMnemonic('E');//set hotkey jmb.add(editmenu);//add menu"Format"to menu bar JMenu formatmenu=newJMenu("Format");formatmenu.setMnemonic('T');//set hotkey jmb.add(formatmenu);//add menu"Tool"to menu bar JMenu toolmenu=new JMenu("Tool");toolmenu.setMnemonic('L');jmb.add(toolmenu);//add menu"Help"to menu bar JMenu helpmenu=new JMenu("Help");helpmenu.setMnemonic('H');//set hotkey jmb.add(helpmenu);//add menu"Exit"to menu bar JMenu exitmenu=new JMenu("Exit");exitmenu.setMnemonic('X');jmb.add(exitmenu);//add menu item with mnemonics to menu"File"filemenu.add(jminew=new JMenuItem("New",'N'));jminew.setIcon(new ImageIcon("images/Handle.gif"));filemenu.add(jmiopen=new JMenuItem("Open",'O'));jmiopen.setIcon(new ImageIcon("images/folderOpen.gif"));filemenu.add(jmisave=new JMenuItem("Save",'S'));jmisave.setIcon(new ImageIcon("images/3.gif"));filemenu.addSeparator();filemenu.add(jmisaveas=new JMenuItem("Save as"));jmisaveas.setIcon(new ImageIcon("images/7.gif"));//set keyboard accelerators jminew.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK));jmiopen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MASK));jmisave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK));//add menu item with mnemonics to menu"Edit"editmenu.add(jmicut=new JMenuItem("Cut",'X'));jmicut.setIcon(new ImageIcon("images/face1.gif"));editmenu.add(jmicopy=new JMenuItem("Copy",'C'));jmicopy.setIcon(new ImageIcon("images/face2.gif"));editmenu.add(jmiplaster=new JMenuItem("Plaster",'V'));jmiplaster.setIcon(new ImageIcon("images/face3.gif"));editmenu.addSeparator();editmenu.add(jmiall=new JMenuItem("All"));jmiall.setIcon(new ImageIcon("images/face4.gif"));//set keyboard accelerators jmicut.setAccelerator( KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK));jmicopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK));jmiplaster.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK));jmiall.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK));//add menu item with mnemonics to menu"Format"formatmenu.add(jmifont=new JMenuItem("Font"));jmifont.setIcon(new ImageIcon("images/face12.gif"));formatmenu.addSeparator();formatmenu.add(jmicolor=new JMenuItem("Color"));jmicolor.setIcon(new ImageIcon("images/face13.gif"));//add menu item with mnemonics to menu"Format"toolmenu.add(jminotepad=new JMenuItem("MS Notepad"));jminotepad.setIcon(new ImageIcon("images/face5.gif"));toolmenu.addSeparator();toolmenu.add(jmicalculator=new JMenuItem("MS Calculator"));jmicalculator.setIcon(new ImageIcon("images/face11.gif"));//add menu item with mnemonics to menu"Help"helpmenu.add(jmiabout=new JMenuItem("About"));jmiabout.setIcon(new ImageIcon("images/face10.gif"));//add menu item with mnemonics to menu"Exit"exitmenu.add(jmiexit=new JMenuItem("Exit"));jmiexit.setIcon(new ImageIcon("images/face6.gif"));//add textpane to notepad//textpane initialize setFont(new Font("Times New Roman",Font.PLAIN,12));JScrollPane scrollpane=new JScrollPane(text);scrollpane.setPreferredSize(new Dimension(600,500));getContentPane().add(scrollpane);///set the name of control,set the listenerjminew.addActionListener(this);jmiopen.addActionListener(this);jmisave.addActionListener(this);jmisaveas.addActionListener(this);jmicut.addActionListener(this);jmicopy.addActionListener(this);jmiplaster.addActionListener(this);jmiall.addActionListener(this);jmifont.addActionListener(this);jmicolor.addActionListener(this);jminotepad.addActionListener(this);jmicalculator.addActionListener(this);jmiabout.addActionListener(this);jmiexit.addActionListener(this);///affair dispose public void actionPerformed(ActionEvent e) //JMenuItem mi=(JMenuItem)e.getSource();String name=e.getActionCommand();//the methodological of jminew if(e.getSource()instanceof JMenuItem)//new if("New".equals(name))text.setText("");file=null;//open if("Open".equals(name))if(file!=null)filechooser.setSelectedFile(file);int returnVal=filechooser.showOpenDialog(Notepad.this);if(returnVal==JFileChooser.APPROVE_OPTION)file=filechooser.getSelectedFile();///the operation for"open"tryFileReader fr=new FileReader(file);int len=(int)file.length();char buffer=new char[len];fr.read(buffer,0,len);fr.close();text.setText(new String(buffer));catch(Exception e_open)e_open.printStackTrace();//save if("Save".equals(name))if(file!=null)filechooser.setSelectedFile(file);int returnVal=filechooser.showSaveDialog(Notepad.this);if(returnVal==JFileChooser.APPROVE_OPTION)file=filechooser.getSelectedFile();tryFileWriter fw=new FileWriter(file);fw.write(text.getText());fw.close();catch(Exception e_save)e_save.printStackTrace();//cut if("Cut".equals(name))text.cut();//copy if("Copy".equals(name))text.copy();//plaster if("Plaster".equals(name))text.paste();//All if("All".equals(name))text.selectAll();//font if("Font".equals(name))//color if("Color".equals(name))color=JColorChooser.showDialog(Notepad.this,"",color);text.setForeground(color);//ms notepad if("MS Notepad".equals(name))tryString command="notepad.exe";Process child=Runtime.getRuntime().exec(command);catch(IOException ex)//ms calculator if("MS Calculator".equals(name))tryString command="calc.exe";Process child=Runtime.getRuntime().exec(command);catch(IOException ex)//exit if("Exit".equals(name))System.exit(0);//about if("About".equals(name))about.setLayout(new GridLayout(6,1));about.setTitle("Notepad About.");about.setSize(320,280);about.getContentPane().setBackground(Color.yellow);//add image on the label JLabel jlbfirst=new JLabel();jlbfirst.setIcon(new ImageIcon("images/wx2.gif"));about.getContentPane().add(jlbfirst);about.getContentPane().add(new JLabel("Star(X)"));about.getContentPane().add(new JLabel("Edition 1.0(author:Hu MingXing)"));about.getContentPane().add(new JLabel("copyrightpossession(C)2019.2.3 Star Corp."));about.getContentPane().add(new JLabel("The product accord with consumer agreement"));about.setModal(true);about.show();特别声明:1:资料来源于互联网,版权归属原作者2:资料内容属于网络意见,与本账号立场无关3:如有侵权,请告知,立即删除。
记事本java程序设计报告~ 第1学期《Java程序设计》课程报告项目:日历记事本专业:计算机科学与技术学号: 10570235姓名:常兆华班级:计算机2班分数:项目说明目录第一部分、项目整体概述 (3)页第二部分、我的任务 (5)页第三部分、代码和详细注释 (6)页第四部分、心得体会 (14)页第一部分、项目整体概述日历记事本----------带有日程提醒功能的日历。
2.显示信息:用户能够看到这个月的信息,包括年份、日期等。
点击翻页按钮能够查询前一个月的日期,也能够向后翻页查询下一个月的日期。
同样,能够根据年份查询不同年份的日期。
日期的显示有一些优化,用户不但能够查询到本月份的信息,还能够根据上个月与下个月的日期填充来方便查询日期和星期。
3.定时提醒:用户能够针对某一天来添加、删除和编辑这一天的日程提醒信息当系统时间和提醒时间相吻合时,给出具有提示信息的对话框。
4.查询信息:用户能够查询到某个月的所有的提示信息。
日历记事本共有4个java源文件。
CalendarPad.java该java文件生成的类负责创立本日历记事本程序主窗口。
该类含有main方法,程序从该类开始执行。
Year.java该文件负责创立管理年份的对象。
Month.java该文件负责创立管理月份的类对象。
NotePad.java该文件负责创立记事本。
截图:初始界面可输入年份查看相应的日历与记事本第二部分、我的任务具体任务:资料查找,汇总及需求分析,负责日历的编写,和板块的布局输出等。
编写大致思路:我主要负责这个项目中日历的编写和输出显示的一部分。
经过调查自己电脑中的日历记事本和大家纸质的日历记事本,我知道若想完整地显示一个月的信息至少需要一个首先需要一个7*7的网格,要用到GridLayout网格设置语言。
其中每一列的顶层能够称它为title“标题”,也就是显示“星期几”,表头显示这个月所在的年份与月份。
随后对日期进行编号,判断闰平年、大小月等必要的程序。
Java 日历记事本课程设计报告在设计日历记事本时,需要编写6个JAVA源文件:、、、、和效果图如下. CalendarWindow 类import .*;import .*;import .*;import .*;public class CalendarWindow extends JFrameimplements 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= ;public CalendarWindow(){dir=new File("./dailyRecord");();showDay=new JTextField[42];for(int i=0;i<;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=();(new Date());year=;month=+1; day=;(year);(month);(day);(calendarMessage);(showDay); (year,month,day);();doMark(); calendarImage=new CalendarImage();(new File(""));clock=new Clock();JSplitPane splitV1=new JSplitPane,calendarPad,calendarImage); JSplitPane splitV2=new JSplitPane,notePad,clock);JSplitPane splitH=new JSplitPane,splitV1,splitV2); add(splitH,; showYear=new JTextField(""+year,6);(new Font("TimesRoman",,12));JshowMonth=new JTextField(""+month,4); (newFont("TimesRoman",,12));JnextYear=new JButton(" 下年"); previousYear=new JButton(" 上年"); nextMonth=new JButton(" 下月"); previousMonth=new JButton(" 上月");(this);(this);(this);(this);JPanel north=new JPanel();(previousYear);(showYear);(nextYear);(previousMonth);(showMonth);(nextMonth);add(north,;saveDailyRecord=new JButton("deleteDailyRecord=new JButton("readDailyRecord=new JButton("(this);(this);(this); JPanel pSouth=new JPanel();(saveDailyRecord);(deleteDailyRecord);(readDailyRecord); add(pSouth,;getPicture=new JButton(" 选择日历图像 "); (this);(getPicture); add(pSouth,;setVisible(true); setBounds(60,60,660,480);保存日志 "); 删除日志 "); 读取日志 ");validate();setDefaultCloseOperation;}public void actionPerformed(ActionEvent e){ if()==nextYear){ year++;(""+year);(year);(calendarMessage);();(year,month,day);doMark();}else if()==previousYear){year--;(""+year);(year);(calendarMessage);();(year,month,day);doMark();}else if()==nextMonth){month++;if(month<1) month=12; (""+month);(month);(calendarMessage);();(year,month,day); doMark();}else if()==previousMonth){month--;if(month<1) month=12; (""+month);(month);(calendarMessage);();(year,month,day); doMark();}else if()==showYear){String s=().trim();char a[]=(); boolean boo=false;for(int i=0;i<;i++) if(!(a[i])))boo=true;if(boo==true)(this, " 您输入了非法年份"," 警告",;else if(boo==false) year=(s);(""+year);(year);(calendarMessage);();(year,month,day);doMark();}else if()==saveDailyRecord){(dir,year,month,day);doMark();}else if()==deleteDailyRecord){(dir,year,month,day);doMark();}else if()==readDailyRecord){(dir,year,month,day);}else if () ==getPicture ) {FileDialog fd=new FileDialog(this," 打开文件对话框");(true);String fileopen = null, filename = null;fileopen = ();filename = ();(new File(fileopen,filename));}}public void mousePressed(MouseEvent e){JTextField text=(JTextField)();String str=().trim();try{ day=(str);}catch(NumberFormatException exp){}(day);(year,month,day);}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}public void mouseClicked(MouseEvent e){}public void focusGained(FocusEvent e){ Component com=(Component)();J}public void focusLost(FocusEvente){ Component com=(Component)();(backColor);}public void doMark(){for(int i=0;i<;i++){showDay[i].removeAll();String str=showDay[i].getText().trim();try{int n=(str);if(isHaveDailyRecord(n)==true){JLabel mess=new JLabel(" 有");(new Font("TimesRoman",,11));JshowDay[i].add(mess);}}catch(Exception exp){}}();();}public boolean isHaveDailyRecord(int n){String key=""+year+""+month+""+n;String [] dayFile=();boolean boo=false;for(int k=0;k<;k++){if(dayFile[k].equals(key+".txt")){ boo=true;break;}} return boo;}public String getPicture_address() {String address = null;try {InputStream outOne = new FileInputStream("");ObjectInputStream outTwo = new ObjectInputStream(outOne); try { address = (String) ();} catch (Exception ex) {}();} catch (IOException eee) {}if (address != null) {return address;} else {return "";}}public void actionPerformed1(ActionEvent e) {if ().equals(" 更改图片背景")) {FileDialog dia = new FileDialog(this, "选择图片", ;(true);(true);if (() != null) && () != null)) {try {FileOutputStream inOne = new FileOutputStream( "");ObjectOutputStream inTwo =new ObjectOutputStream(inOne);() + ());();} catch (IOException ee) {}String picturename = getPicture_address();(new File(picturename));}}}public static void main(String args[]){new CalendarWindow();}}CalendarPad 类import .*; import .*;import .*;import class CalendarPad extends JPanel{int year,month,day;CalendarMessage calendarMessage;JTextField[] showDay;JLabel title[];String[] 星期={"SUN 日","MON —","TUE 二","WED 三","THU 四","FRI 四","SAT 六"};JPanel north,center;public CalendarPad(){setLayout(new BorderLayout());north=new JPanel();(new GridLayout(1,7)); center=new JPanel();(new GridLayout(6,7)); add(center , );add(north, );title=new JLabel[7];for(int j=0;j<7;j++){title[j]=new JLabel();title[j].setFont(new Font("TimesRoman", ,12)); title[j].setText( 星期[j]);title[j].setHorizontalAlignment;title[j].setBorder());(title[j]);}title[0].setForeground;title[6].setForeground;}public void setShowDayTextField(JTextField[]text){ showDay=text;for(int i=0;i<;i++){showDay[i].setFont(new Font("TimesRoman", ,15));showDay[i].setHorizontalAlignment;showDay[i].setEditable(false);(showDay[i]);}}public void setCalendarMessage(CalendarMessage calendarMessage){=calendarMessage;}public void showMonthCalendar(){String[] a=();for(int i=0;i<42;i++)showDay[i].setText(a[i]);validate();}}CalendarMesssage 类import class CalendarMessage {int year=-1,month=-1,day=-1;public int getYear(){return year;}public void setMonth(int month){if(month<=12&&month>=1)=month;else=1;}public int getMonth(){return month;}public void setDay(int day){=day;}public int getDay(){return day ;}public String []getMonthCalendar(){String[] day=new String[42];Calendar rili =();(year, month-1,1);int 星期几= )-1;int dayAmount=0;if(month==1||month==3||month==5||month==7||month==8||month==10||m onth==12)dayAmount=31;if(month==4||month==6||month==9||month==11) dayAmount=30;if(month==2)if(((year%4==0)&&(year%100!=0)||year%400==0)) dayAmount=29;elsedayAmount=28;for(int i=0;i< 星期几;i++)day[i]="";for(int i= 星期几,n=1;i< 星期几+dayAmount;i++){day[i]=(n);n++;}for(int i= 星期几+dayAmount;i<42;i++)day[i]="";return day;}public void setYear(int year) {= year;}}NotePad 类import .*;import .*;import .*;import class NotePad extends JPanel implements ActionListener { JTextArea text;JTextField showMessage;JPopupMenu menu;JMenuItem itemCopy, itemCut, itemPaste, itemClear, btn;public NotePad() {showMessage = new JTextField();J(new Font("TimesRoman", , 16));());(false);menu = new JPopupMenu(); itemCopy = new JMenuItem(" 复制"); itemCut = new JMenuItem(" 剪切"); itemPaste = new JMenuItem(" 粘贴"); itemClear = new JMenuItem(" 清空");btn = new JMenuItem(" 字体");(this);(this);(this);(this);(this);(itemCopy);(itemCut);(itemPaste);(itemClear);(btn);text = new JTextArea(10, 10);(new MouseAdapter() {public void mousePressed(MouseEvent e) { if () ==(text, (), ());}});setLayout(new BorderLayout());add(showMessage, ;add(new JScrollPane(text), ;}public void setShowMessage(int year, int month, int day) { ("" + year + " 年" + month + " 月" + day + " 日");J(new Font(" 宋体", , 15));}public void save(File dir, int year, int month, int day) { String dailyContent = ();String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = (); boolean boo = false;for (int k = 0; k < ; k++) {if (dayFile[k].startsWith(key)) { boo = true; break;}} if (boo) {String m = "" + year + " 年" + month + " 月" + day+ " 已有日志,将新的内容添加到日志吗";int ok = (this, m, "", if (ok == {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f,"rw");long fileEnd = ();byte[] bb = ();(fileEnd);(bb);();} catch (IOException exp) {}}} else {String m = "" + year + "年" + month + " 月 " + day + " 日志,保存日志吗 ";int ok = (this, m, " 询问 ", if (ok == {try {File f = new File(dir, fileName);RandomAccessFile out = new RandomAccessFile(f,long fileEnd = ();byte[] bb = ();(fileEnd);(bb);();} catch (IOException exp) {} }}}public void delete(File dir, int year, int month, int day) { String key = "" + year +"" + month + "" + day; String[] dayFile = ();boolean boo = false;for (int k = 0; k < ; k++) {if (dayFile[k].startsWith(key)) {boo = true;break;}} if (boo) {String m = " 删除 " + year + " 年 " + month + " 月 " + day + " 日 的日志还没有 "rw");吗";int ok = (this, m, " 询问", if (ok == {String fileName = "" + year + "" + month + "" + day + ".txt";File deleteFile = new File(dir, fileName);();}}else {String m = "" + year + "" + month + "" + day + "";(this, m, " 提示",public void read(File dir, int year, int month, int day) {String fileName = "" + year + "" + month + "" + day + ".txt";String key = "" + year + "" + month + "" + day;String[] dayFile = ();boolean boo = false;for (int k = 0; k < ; k++) {if (dayFile[k].startsWith(key)) { boo = true;break;}} if (boo) {String m = "" + year + "" + month + "" + day + "" int ok = (this, m, " 询问", if (ok == {(null);try {File f = new File(dir, fileName);FileReader inOne = new FileReader(f);BufferedReader inTwo = new BufferedReader(inOne);String s = null;while ((s = ()) != null)(s + "\n");();();} catch (IOException exp) {}}} else {String m = "" + year + "" + month + "" + day + "";public void actionPerformed(ActionEvent e) { if () ==itemCopy)();else if () == itemCut)();else if () == itemPaste)();else if () == itemClear)(null);if () == btn) {JFontDialog nFD = new JFontDialog("(true);(true);}}}class JFontDialog extends JDialog {private static final long serialVersionUID = 1L;JList fontpolics, fontstyle, fontsize;(this, m, "提示 ",选择字体 ");JTextField fontpolict, fontstylet, fontsizet;String example;JLabel FontResolvent;JButton buttonok, buttoncancel;Font myFont;public JFontDialog(String title) {Container container = getContentPane();(new BorderLayout());JPanel panel = new JPanel();(new GridLayout(2, 1));JPanel FontSet, FontView;FontSet = new JPanel(new GridLayout(1, 4));FontView = new JPanel(new GridLayout(1, 2));example = "AaBbCcDdEe";FontResolvent = new JLabel(example, ;ListSelectionListener selectionListenernew ListSelectionListener() {public void valueChanged(ListSelectionEvent e){ if (((JList) ()).getName().equals("polic")){ ((String) ());(new Font(),().getStyle(), FontResolvent.getFont().getSize()));} }; }if (((JList) ()).getName().equals("style")) { ((String) ());(new Font().getFontName(), (),().getSize()));}if (((JList) ()).getName().equals("size")) { ((String) ());try {());} catch (Exception excepInt) {().getSize()+ "");}(new Font().getFontName(), ().getStyle(),())));}KeyListener keyListener = new KeyListener() {public void keyPressed(KeyEvent e) {if () == 10) {if (((JTextField) ()).getName().equals("polic")) {(new Font(),().getStyle(),().getSize()));}if (((JTextField) ()).getName().equals("style")) { ((String) fontstyle.getSelectedValue());(new Font().getFontName(), (),().getSize()));}if (((JTextField) ()).getName().equals("size")) { try {());} catch (Exception excepInt) {().getSize()Illi );}(new Font().getFontName(), () .getStyle(),(fontsizet .getText())));}}}public void keyReleased(KeyEvent e) {}public void keyTyped(KeyEvent e) {}};etLocalGraphicsEnvironment().getAllFonts();int taille = ;String[] policnames = new String[taille];for (int i = 0; i < taille; i++) {policnames[i] = fonts[i].getName();}fontpolics = new JList(policnames);("polic");(selectionListener);(6);fontpolict = new JTextField(policnames[0]);("polic");(keyListener);JScrollPane jspfontpolic = new JScrollPane(fontpolics);(new BoxLayout(Fontpolic, );(fontpolict);(jspfontpolic);import .*; import .*;public class CalendarImage extends JPanel{File imageFile;Image image;Toolkit tool;CalendarImage(){tool=getToolkit();}public void setImageFile(File f){imageFile=f;try{ image=().toURL());}catch(Exception exp){}repaint();}public void paintComponent(Graphics g){(g);int w=getBounds().width;int h=getBounds().height;(image, 0, 0, w, h, this);}}Clock 类import class Clock extends JPanelimplements ActionListener {Date date;secondTime;int hour,munite,second;Line2D secondLine,muniteLine,hourLine;Line2D m=new (0,0,0,0);Line2D s=new (0,0,0,0);int a,b,c,width,height;double pointSX[]=new double[60],pointSY[]=new double[60],pointMX[]=new double[60],pointMY[]=new double[60],pointHX[]=new double[60],pointHY[]=new double[60];Clock(){setBackground;initPoint();secondTime=new secondLine=new (0,0,0,0);muniteLine=new (0,0,0,0);hourLine=new (0,0,0,0);();}private void initPoint(){width=getBounds().width;height=getBounds().height;pointSX[0]=0;pointSY[0]=-height/2*5/6;pointMX[0]=0; pointMY[0]=-(height/2*4/5);pointHX[0]=0;pointHY[0]=-(height/2*2/3);double angle=6*180;for(int i=0;i<59;i++){pointSX[i+1]=pointSX[i]*(angle)(angle)*pointSY[i];pointSY[i+1]=pointSY[i]*(angle)+pointSX[i]*(angle);pointMX[i+1]=pointMX[i]*(angle)(angle)*pointMY[i];pointMY[i+1]=pointMY[i]*(angle)+pointMX[i]*(angle);pointHX[i+1]=pointHX[i]*(angle)(angle)*pointHY[i];pointHY[i+1]=pointHY[i]*(angle)+pointHX[i]*(angle);}for(int i=0;i<60;i++){pointSX[i]=pointSX[i]+width/2;pointSY[i]=pointSY[i]+height/2;pointMX[i]=pointMX[i]+width/2;pointMY[i]=pointMY[i]+height/2;pointHX[i]=pointHX[i]+width/2; pointHY[i]=pointHY[i]+height/2;}}public void paintComponent(Graphics g){(g);initPoint();for(int i=0;i<60;i++){int m=(int)pointSX[i];int n=(int)pointSY[i];if(i%5==0){ if(i==0||i==15||i==30||i==45){ int k=10;J(m-k/2, n-k/2, k, k);}else{int k=7;);(m-k/2, n-k/2, k, k);}}else{int k=2;J(m-k/2, n-k/2, k, k);}}(width/2-5, height/2-5, 10, 10);Graphics2D g_2d=(Graphics2D)g;J(secondLine);BasicStroke bs=new BasicStroke(2f,,;(bs);(muniteLine); bs=new BasicStroke(2f,,;(bs);J(hourLine); bs=new BasicStroke(4f,,;(bs);}public void actionPerformed(ActionEvent e){ if()==secondTime){ date=new Date();String s=(); hour=(11, 13));munite=(14, 16)); second=(17, 19));int h=hour%12; a=second; b=munite;c=h*5+munite/12;(width/2,height/2,(int)pointSX[a],(int)pointSY[a]);(width/2,height/2,(int)pointMX[b],(int)pointMY[b]);(width/2,height/2,(int)pointHX[c],(int)pointHY[c]); repaint(); if ((munite==0)&&(second==0)){} }try{File f=new File("");URI uri=();URL url=();AudioClip aau;aau=(url);();}catch(MalformedURLException ex){();}}}。
java课程设计日历记事本湖南人文科技学院计算机系2009年6月19日- 1 -::1;(1)为用户提供一个简便的日历记事本;(2)对java技术的进一步了解和简单的运用;(3)初步的接触软件工程;26月8日分析课题、分配任务;对题目进行初步分析 6月9日建立模型,完成整体设计以及功能模块分析 6月10日确立每个类的功能,完成对算法的分析 6月11日完成CalendarPad类的设计6月12日完成对Year类的设计6月13日完成对Month类的设计6月14日完成对NotePad类的设计6月15日紧系程序测试与修改6月16日完成设计,整理说明书6月19日打包发布程序设计成绩:(教师填写)指导老师:(签字)2009年月日- 2 -摘要 ..................................................................... ................................................................... - 4 - 1. 引言 ..................................................................... ...................................................................... - 5 - 2.设计目的与任务 ..................................................................... ................................................... - 5 - 3.设计方案...................................................................... ............................................................... - 6 -3.1 总体设计 ..................................................................... ................................................... - 6 -3.2设计要求 ..................................................................... .................................................... - 6 -3.3系统的主要功能...................................................................... ....................................... - 6 -3.4系统功能结构图...................................................................... ....................................... - 6 -3.5运行功能(截图) ................................................................... ..................................... - 7 -4.结束语 ..................................................................... .................................................................... - 9 - 5.致谢 ..................................................................... .................................................................... - 9 - 6.参考文献...................................................................... ............................................................. - 10 - 7.附录A:源程序 ..................................................................... .................................................... - 11 - 8附录B:编码规范 ..................................................................... ............................................. - 24 -- 3 -本课程设计通过代码实现将理论知识和具体实践相结合,巩固提高了对JAVA的相关方法与概念的理解,使学生的发散思维及动手能力进一步加强,加强对计算机及软件工程的进一步了解。
GUI综合应用项目:日历记事本设计一、实训目的1、巩固JAVA程序设计的基本理论知识。
2、将理论知识和实践结合起来,将理论知识应用到实践中,编写应用程序。
3、通过实训,掌握基本的编程思想方法,具备一定的编程能力。
二、实训的基本要求2.1 理论要求1、熟悉JAVA基本语法及三种基本结构(顺序、选择、循环)。
2、熟悉JAVA面向对象程序设计思想。
3、熟悉JAVA的类抽象、封装、继承、多态的特性。
在此基础上,多查阅资料,独立思考完成程序代码,并写出详细的设计书。
2.2 设备要求JDK1.5.0以上版本,JBuilder或Eclipse3.0。
三、实训内容运用JA V A语言设计一个GUI 界面的日历记事本。
系统将日历、记事本结合在一起,用户可以方便地在任何日期记载有关内容以及查看某个日期记载的内容。
其内容为:1、界面的左侧是日历。
该日历可以按年前后翻动,当鼠标单击“上一年”按钮时,当前日历的年份将减一;当鼠标左键单击“下年”按钮,当前日历的年份将加一。
2、也可以在某年内按月前后翻动。
当鼠标左键单击“上月”按钮时,当前日历的月份将减一;当鼠标左键单击“下月”当前日历表的月份将加一。
3、使用鼠标左键在要选择的日期上单击,如有记事内容,程序将弹出对话框提示该日有记事内容,提示用户是否用记事本显示该内容。
4、选择具体日期后,可以将记事本的内容保存起来,形成一个日志。
5、日历记事本共有4 个Java 源文件:MyCalendar.java,用来描述日期类;CalendarPad.Java,负责创建日历记事本主窗口,该文件含有main方法,程序从该类开始执行;CalendarFrame.java,用来描述日历记事本窗体;NotePad.Java,负责创建记事本(也可以不单独定义类,将其放在日历记事本窗体中定义)。
6、运行效果图7、附加功能:在完成以上功能基础上为日历记事本增加农历显示、添加背景图片、增加重要事务提醒等功能。
java课程设计日历记事本湖南人文科技学院计算机系2009年6月19日- 1 -::1;(1)为用户提供一个简便的日历记事本;(2)对java技术的进一步了解和简单的运用;(3)初步的接触软件工程;26月8日分析课题、分配任务;对题目进行初步分析 6月9日建立模型,完成整体设计以及功能模块分析 6月10日确立每个类的功能,完成对算法的分析 6月11日完成CalendarPad类的设计6月12日完成对Year类的设计6月13日完成对Month类的设计6月14日完成对NotePad类的设计6月15日紧系程序测试与修改6月16日完成设计,整理说明书6月19日打包发布程序设计成绩:(教师填写)指导老师:(签字)2009年月日- 2 -摘要 ..................................................................... ................................................................... - 4 - 1. 引言 ..................................................................... ...................................................................... - 5 - 2.设计目的与任务 ..................................................................... ................................................... - 5 - 3.设计方案...................................................................... ............................................................... - 6 -3.1 总体设计 ..................................................................... ................................................... - 6 -3.2设计要求 ..................................................................... .................................................... - 6 -3.3系统的主要功能...................................................................... ....................................... - 6 -3.4系统功能结构图...................................................................... ....................................... - 6 -3.5运行功能(截图) ................................................................... ..................................... - 7 -4.结束语 ..................................................................... .................................................................... - 9 - 5.致谢 ..................................................................... .................................................................... - 9 - 6.参考文献...................................................................... ............................................................. - 10 - 7.附录A:源程序 ..................................................................... .................................................... - 11 - 8附录B:编码规范 ..................................................................... ............................................. - 24 -- 3 -本课程设计通过代码实现将理论知识和具体实践相结合,巩固提高了对JAVA的相关方法与概念的理解,使学生的发散思维及动手能力进一步加强,加强对计算机及软件工程的进一步了解。
课程设计报告( 2012-- 2013年度第2学期)日历记事本专业 计算机科学与技术学生姓名董文龙班级 计算机116 学号1110704603 指导教师 徐秀芳 完成日期2013.7目录目录 (2)1 概述 (4)1.1课程设计目的 (4)1.2课程设计内容和要求 (4)2 系统需求分析 (5)2.1系统目标 (5)2.2主体功能 (5)2.3开发环境 (5)3 系统总体设计 (5)3.1系统的功能模块划分 (5)3.2系统流程图 (6)4系统详细设计 (6)4.1主窗口模块设计 (6)4.1.1 效果图 (6)4.1.2 类的主要成员变量和方法 (7)4.1.3 主要程序代码 (8)4.2日期模块设计 (19)4.2.1 效果图 (19)4.2.2 类的主要成员变量和方法 (19)4.2.3 主要程序代码 (20)4.3日历模块设计 (21)4.3.1 效果图 (21)4.3.2 类的主要成员变量和方法 (22)4.3.3 主要程序代码 (22)4.4记事本模块设计 (24)4.4.1 效果图 (24)4.4.2 类的主要成员变量和方法 (24)4.4.3 主要程序代码 (25)4.5图像模块设计 (34)4.5.1 效果图 (34)4.5.2 类的主要成员变量和方法 (34)4.5.3 主要程序代码 (35)4.6时钟模块设计 (36)4.6.1效果图 (36)4.6.2 类的主要成员变量和方法 (36)4.6.3主要程序代码 (37)5 代码调试 (41)6 软件发布 (42)7 小结 (42)参考文献 (44)日历记事本日历记事本1 概述1.1 课程设计目的(1)加深对《Java语言与面向对象技术》课程基础知识的理解,掌握Java语言面向对象程序设计的开发方法和步骤;(2)进一步理解面向对象程序设计的思想和方法,利用Java语言进行程序设计的能力;(3)课程设计将课本上的理论知识和实际应用相结合,锻炼学生发现问题、分析问题和解决问题的能力。
2010级Java 程序课程设计报告学 院 : 信息与电子工程学院 专 业 : 计算机科学与技术 班 级 : 计算机102班 学 号 :110021051 11002104、110021052 学生姓名 :傅攀攀(组长)、 陆建浩、 刘凌阳指导教师 : 许加兵二○一二年 一 月报告题目: 基于Java 的日历记事本的设计与开发Java程序课程设计任务书一、主要任务与目标:1.掌握Java语言,能熟练使用Javascript,Jcreator等开发工具,2.熟悉软件分析和设计方法。
3.使用所学知识开发一个基于Java的日历记事本。
二、主要内容与基本要求:设计GUI界面的日历记事本。
系统将日历、记事本功能结合在一起,用户可以方便地在任何日期记录下有关内容或查看某个日期的记录内容。
1. 系统界面的左侧是日历。
该日历可以按年份前后翻动,鼠标单击“上年”按钮时,当前的日历的年份减一;当鼠标左键单击“下年”按钮,当前日历年份加一。
2. 该日历也可以在某年内按月前后翻动,鼠标单击“上月”按钮时,当前的日历的月份减一;当鼠标左键单击“下月”按钮,当前日历月份加一。
3. 使用鼠标左键单击选定的日期,如已有记录内容,系统将弹出对话框提示该日已有记录内容,并询问用户是否用记事本显示该内容。
三、开发工具:JCreator Pro、JDK、MyEclipse、UML、SQLServer2008等。
四、计划进度:1.12月27日:分组确定组员,搜集资料、查阅文献,确定选题。
2.12月28日--12月31日:日历记事本的需求分析,设计,功能模块完善3. 1月1日-- 1月2日:基于日历记事本信息存储的数据库分析与设计4.1月3日--1月5日:主要模块程序流程图、编程实现游戏功能5.1月3日--1月5日:日历记事本调试、测试、修改与完善6.1月6日:日历记事本课程设计报告撰写7.1月6日:日历记事本课程设计报告答辩五、主要参考文献[01]耿祥义,张跃平.Java课程设计(第二版)[M].清华大学出版社.2008年11月[02]耿祥义,张跃平.Java2实用教程(第三版)[M].清华大学出版社.2006年8月六、小组分工傅攀攀(组长):资料汇总,撰写任务书,撰写课程设计报告,部分代码编写注释,添加部分功能,总体设计。
《面向对象程序设计》课程设计报告题目:《日记本的设计与实现》课程设计学院:信息工程姓名:xxxx学号:**********专业:软件工程班级:软工1101班指导教师:xxxx二0一二年十二月十四日目录1.引言 (2)2.设计目的与任务 (3)3.设计方案 (3)3.1总体设计 (3)3.2设计要求 (3)3.3系统的主要功能 (4)3.4开发环境 (4)3.5系统的功能模块划分与系统流程图 (4)3.5.1系统的功能模块划分 (4)3.5.2万年历模块流程图 (5)3.5.3日记本模块流程图 (6)3.6各个类说明 (6)3.6.1主类NoteBook (6)3.6.2记事本Note类 (7)3.6.3左侧面板LeftPane类 (7)3.6.4月份显示MonthPane类 (8)3.6.5年月显示YearMonth类 (8)3.6.6背景音乐Music类 (8)3.6.7日期获取DateTime类 (9)3.6.8右侧记事本显示NotePane类 (9)3.6.9记事本弹出菜单NotePopupMenu类 (10)4.各种功能截图 (10)5.课程设计总结 (14)6.个人心得体会 ............................................................................... 错误!未定义书签。
7.附录 (15)摘要摘要本课程设计通过代码实现将理论知识和具体实践相结合,巩固提高了对JAVA的相关方法与概念的理解,使学生的发散思维及动手能力进一步加强,加强对计算机及软件工程的进一步了解。
在这个课程设计中,做成了一个有日历标记的记事本软件,日记本面板由日历、记事本、图片、时钟四部分组成。
日历部分可以选择不同的年份、月份、日期和星期;记事本模块可以实现查看,保存,删除日志等操作;并且每一步操作都有相应提示;图片模块可以显示预设的图片;时钟模块可以用时钟来显示当前时间。
枣庄学院信息科学与工程学院课程设计任务书题目时钟日历记事本学号: ________________________________________ 姓名: ________________________________________ 专业:计算机科学与技术 __________________ 课程:Java程序设计____________________ 指导教师: _________________ 职称:讲师完成时间:2015年11月----2015年12月枣庄学院信息科学与工程学院制2015 年11 月27 日课程设计任务书及成绩评定课程设计的任务和具体要求使用Java语言开发一款功能完整、界面美观、运行良好的软件,软件题目自拟。
写字板、计算器类似简单的小软件1人1组。
信息管理系统软件最多3人1组。
游戏软件最多2 人1组。
以通用的软件工程制设计规范撰写一个相应的书面文档,在该文档中要包括需求分析、系统设计(软件用例图、系统流程图、数据库设计)、系统详细设计(每个功能模块关键代码和运行截图)。
指导教师签字:日期:2015年11月指导教师评语成绩: __________ 指导教师签字:日期:目录1、引言............................................................ .41.1项目的名称 ................................................... .41.2项目背景和目标 (4)2、需求分析2.1系统概况 (4)2.2功能需求描述.............................................. (5)3、总体设计3.1开发与设计的总体思想 (5)3.2关系图 ................................................. . (5)3.3Java 源文件及其功能........................................ (5)3.4系统详细设计 ............................................. .64、运行结果 (8)5、程序代码5.1CalendarPad ................................................................ ..115.2Clock (20)5.3Mon th (23)5.4Year ........................................................................ ..255.5Notepad ............................................................. .. (26)&总结 (31)1、引言1.1项目的名称时钟日历记事本1.2项目背景和目标目前,很多新的技术领域都涉及到了Java语言,Java语言是面向对象编程,并涉及到网络、多线程等重要的基础知识,因此Java语言也是学习面向对象编程和网络编程的首选语言。
用Java实现日历记事本 信息与计算科学专业课程设计 用Java实现日历记事本 1. 实验目的 掌握RandomAccessFile类的使用;掌握字符输入、输出流和缓冲输入、输出流的使用。
2. 实验要求 实验前,应事先熟悉相关知识点,拟出相应的实验操作步骤,明确实验目的和要求;实验过程中,服从实验指导教师安排,遵守实验室的各项规章制度,爱护实验仪器设备;实验操作完成后,认真书写实验报告,总结实验经验,分析实验过程中出现的问题。 3. 实验内容 编程实现日历记事本。具体要求如下: (1)该日历可以通过在文本框中输入年份和月份设置日期,也可按年前后翻动,用鼠标左键单击“上年”和“下年”按钮,将当前日历的年份减一和加一。还可以在某年内按月前后翻动,用鼠标左键单击“上月”和“下月”按钮,将日历的月份减一和加一。 (2)左键单击日历上的日期,可以通过右侧的记事本(文本区)编辑有关日志,并将日志保存到一个文件,该文件的名字是由当前日期组成的字符序列。用户可以读取、删除某个日期的日志,也可以继续向某个日志添加新的内容。在保存、删除和读取日志时都会先弹出一个确认对话框,以确认保存、删除和读取操作。 (3)当某个日期有日志时,该日期以粗体16号字显示,表明这个日期有日志;当用户删除某个日期的日志后,该日期恢复原来的外观。 实现效果图(参考)如下: 提示:(1)组件调用public void setFont(Font f)方法可以设置组件上的字体,Font类的构造方法为:public Font(String name,int style,int size),其中name是字体的名字,style决定字体的样式(如Font.BOLD表示粗体)size决定字体的大小。(具体请参考JDK API) (2)当左键单击日历上的日期时,如要获取该日期,可通过处理该组件上的鼠标事件来实现。 4.实验步骤、实施过程、关键代码、实验结果及分析说明等 1. CalendarPad类 (1) 进行整体布局,建立日历记事本文件,设置日历卡,把日期按星期顺序排列,并用窗口监视器实现。 (2)用窗口监视器实现,结果如下:
2. Notepad类 (1) 对日期的设置和获取,设置信息条,对文本框进行设置,保存日志、删除日志和读取日志按钮的事件实现。 (2)保存日志按钮事件实现如下: (3)读取日志按钮事件实现如下: (4.)删除日志按钮事件实现如下:
3 Year类 (1)输入年份可以实现输出,给上下年按钮设置监视器,对上下年按钮事件的实现。 (2)其结果如下:
4. Month类 (1)设置上下月监视器,对上下月按钮的事件实现,区分闰年和平年,对天数不同的月份进行分类。 (2)其结果如下: (续上页,可加页) 5 各个类的源代码如下: CalendarPad 类: //CalendarPad.java 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,ActionListener { int year,month,day; Hashtable hashtable; JButton Save,Delete,Read; File file; JTextField showDay[]; JLabel title[]; Calendar Date; int Weekday; NotePad notepad=null; Month ChangeMonth; Year ChangeYear ; String week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"}; 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; ChangeYear=new Year(this); ChangeYear.setYear(year); ChangeMonth=new Month(this); ChangeMonth.setMonth(month); title=new JLabel[7]; showDay=new JTextField[42]; for(int j=0;j<7;j++) { title[j]=new JLabel(); title[j].setText(week[j]); title[j].setBorder(BorderFactory.createRaisedBevelBorder()); title[j].setForeground(Color.blue); leftCenter.add(title[j]); }
for(int i=0;i<42;i++) { showDay[i]=new JTextField(); showDay[i].addMouseListener(this); showDay[i].setEditable(false); leftCenter.add(showDay[i]); }
Save=new JButton("保存日志") ; Delete=new JButton("删除日志") ; Read=new JButton("读取日志") ; Read.addActionListener(this); Save.addActionListener(this); Delete.addActionListener(this); //设置监视器 JPanel pSouth=new JPanel(); pSouth.add(Save); pSouth.add(Delete); pSouth.add(Read); Date=Calendar.getInstance(); Box box=Box.createHorizontalBox(); box.add(ChangeYear); box.add(ChangeMonth); leftNorth.add(box); leftPanel.setLayout(new BorderLayout()); add(leftNorth,BorderLayout.NORTH); leftPanel.add(leftCenter,BorderLayout.CENTER); add(pSouth,BorderLayout.SOUTH); leftPanel.validate();
notepad=new NotePad(this); rightPanel.add(notepad);
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){} }
setCalendar(year,month); addWindowListener(new WindowAdapter() { //设置窗口监视器 public void windowClosing(WindowEvent e) { System.exit(0); } } ); setVisible(true); setBounds(100,60,524,335); validate(); }
public void actionPerformed(ActionEvent e) { if(e.getSource()==Save) { notepad.Save(file,year,month,day); } else if(e.getSource()==Delete) { notepad.Delete(file,year,month,day); } else if(e.getSource()==Read) { notepad.Read(file,year,month,day); } }
public void setCalendar(int year,int month) { //设置日历卡 Date.set(year,month-1,1); Weekday=Date.get(Calendar.DAY_OF_WEEK)-1; if(month==1||month==2||month==3||month==5||month==7 ||month==8||month==10||month==12) { Arrange(Weekday,31);