日歷記事本201120460217_第1頁
日歷記事本201120460217_第2頁
日歷記事本201120460217_第3頁
已閱讀5頁,還剩17頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權,請進行舉報或認領

文檔簡介

1、JAVA程序設計課程設計報告專業(yè):信息管理與信息系統(tǒng)班級:1124602學號:2姓名:鄒瑋指導教師:姜俊坡目錄1 可行性分析 22 .需求分析功能23 .課程設計24. 編碼 35. 系統(tǒng)驗證21216. 總結(jié)1. 可行性分析1. 學習Java程序開發(fā)的環(huán)境搭建與配置,并且在實際運用中學習和和掌握 Java程序開發(fā)的過程2. 通過課程設計進一步掌握Java程序設計語言的基礎內(nèi)容,如用戶圖形界 面設計等3通過親自設計,編寫,調(diào)試程序來擴展知識面和動手操作能力2. 需求分析功能設計一個日歷記事本.具體要求如下:1. 可以設置日歷的日期2. 可以判斷當前日期是否有日志記錄3. 對有日志記錄的日期,可

2、以對該日期的日志記錄進行修改和刪除4. 對沒有日志記錄的日期,可以創(chuàng)建并保存新建的日志記錄3. 課程設計表1日歷記事本系統(tǒng)主面板與日歷板模塊(Cale ndarPad.java類名Cale ndarPadpublic接口MouseListe nerpublicCale ndarPad(i nt, in t,i ntpublic方法設置日歷牌(int,intpublic void排列號碼(int,intpublic voidmain (public static void表2日歷記事本系統(tǒng)年設置模塊 (Year.java類名Yearpublic接口Actio nListe nerpublicse

3、tYear(public void方法getYear(public intactio nPeformed(Actio nEve nt epublic void表3日歷記事本系統(tǒng)月設置模塊(Month.java類名Mon thpublic接口Actio nListe nerpublicsetM on th(public void方法getM on th(public intactio nPeformed(Actio nEve nt epublic void表4日歷記事本系統(tǒng)記事本模塊(NotePad.java類名NotePadpublic接口Actio nListe nerpublic設置信息條

4、(public void設置文本區(qū)(public void方法獲取日志內(nèi)容(public void保存日志(public void刪除日志(public void4. 編碼1.日歷記事本系統(tǒng)主面板與日歷板模塊(CalendarPad.java該模塊設計主要主要包含以下成員變量:年(year月(month日(day存放日期的表 (Hashtable 存放日志的文件 (File主要方法有: 創(chuàng)建程序主面板的構造方法 CalendarPad ) 處理 ActionEvent 事件的接口方法 actionPerformed ) 程序開始運行的 main leftPanel=new JPanel( 。

5、JPanel leftCenter=new JPanel( 。 JPanel leftNorth=new JPanel( 。 leftCenter.setLayout(new GridLayout(7,7 。rightPanel=new JPanel( 。 this.year=year 。 this.month=month 。 this.day=day 。 負責改變年 =new Year(this 。 負責改變年 .setYear(year 。 負責改變月 =new Month(this 。 負責改變月 .setMonth(month 。 title=new JLabel7 。 showDay

6、=new JTextField42 。for(int j=0。 jtitlej=new JLabel( 。titlej.setText(星期j。titlej.setBorder(BorderFactory.createRaisedBevelBorder( 。leftCenter.add(titlej 。title0.setForeground(Color.red 。 title6.setForeground(Color.blue 。 for(int i=0 。 ishowDayi=new JTextField( 。 showDayi.addMouseListener(this 。 showDa

7、yi.setEditable(false 。 leftCenter.add(showDayi 。日歷 =Calendar.getInstance( 。Box box=Box.createHorizontalBox( 。box.add( 負責改變年 。 box.add( 負責改變月 。leftNorth.add(box 。 leftPanel.setLayout(new BorderLayout( 。 leftPanel.add(leftNorth,BorderLayout.NORTH 。 leftPanel.add(leftCenter,BorderLayout.CENTER 。 leftPa

8、nel.add(new Label( 請在年份輸入框輸入所查年份(負數(shù)表示公元前 ,并回車確定 ,BorderLayout.SOUTH 。leftPanel.validate( 。Container con=getContentPane( 。JSplitPane split=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rightPanel con.add(split,BorderLayout.CENTER 。 con.validate( 。hashtable=new Hashtable( 。file=new File( 日歷記事本 .

9、txt 。if(!file.exists(tryFileOutputStream out=newFileOutputStream(file 。ObjectOutputStream objectOut=newObjectOutputStream(out 。objectOut.writeObject(hashtable 。objectOut.close( 。 out.close( 。catch(IOException enotepad=new NotePad(this 。rightPanel.add(notepad 。設置日歷牌 (year,month 。addWindowListener(new

10、 WindowAdapter(public void windowClosing(WindowEvent eSystem.exit(0 。setVisible(true 。setBounds(100,50,524,285 。validate( 。public void 設置日歷牌 (int year,int month日歷 .set(year,month-1,1 。星期幾二日歷.get(Cale ndar.DAY_0F_WEEK-1 。if(month=1|month=2|month=3|month=5|month=7|month=8|month=10|month=12排列號碼(星期幾,31。

11、elseif(month=4|month=6|month=9|month=11排列號碼(星期幾,30。else if(month=2if(year%4=0&year%100!=0|(year%400=0排列號碼(星期幾,29。else排列號碼(星期幾,28。public void 排列號碼 (int 星期幾 ,int 月天數(shù) for(int i=星期幾,n=1。ishowDayi.setText(+nif(n=dayshowDayi.setForeground(Color.green 。showDayi.setFont(new Font(TimesRoman,Font.BOLD,20 。 el

12、seshowDayi.setFont(new Font(TimesRoman,Font.BOLD,12 。showDayi.setForeground(Color.black 。 if(i%7=6showDayi.setForeground(Color.blue 。 if(i%7=0showDayi.setForeground(Color.red 。 n+。for(int i=0。ishowDayi.setText( 。 for(int i= 星期幾 +月天數(shù)。 ishowDayi.setText( 。 public int getYear(return year 。 public void

13、setYear(int y year=y 。 notepad.setYear(year 。 public int getMonth(return month 。 public void setMonth(int m month=m 。 notepad.setMonth(month 。 public int getDay(return day 。 public void setDay(int d day=d 。 notepad.setDay(day 。 public Hashtable getHashtable(return hashtable 。 public File getFile(ret

14、urn file 。public void mousePressed(MouseEvent e JTextField source=(JTextFielde.getSource(tryday=Integer.parseInt(source.getText( 。 notepad.setDay(day 。 notepad. 設置信息條 (year,month,day 。 notepad. 設置文本區(qū) (null 。 notepad. 獲取日志內(nèi)容 (year,month,day 。 catch(Exception eepublic void mouseClicked(MouseEve nt epu

15、blic void mouseReleased(MouseEve nt e public void mouseEntered(MouseEvent e public void mouseExited(MouseEvent e public static void main(String argsCalendar calendar=Calendar.getInstance( 。 int y=calendar.get(Calendar.YEAR 。 int m=calendar.get(Calendar.MONTH+1 。 int d=calendar.get(Calendar.DAY_OF_MO

16、NTH 。 new CalendarPad(y,m,d 。2. 日歷記事本系統(tǒng)年設置模塊 (Year.java 該模塊用于實現(xiàn)日歷記事本系統(tǒng)中關于年的設置 模塊中包含的主要成員變量有用于改變年的按鈕 (Jbutton 明年 去年 ,顯 示年的文本框 (JTextField模塊中包含的主要方法有用于設置年的方法 (setYear, 用于獲取年的方 法(getYear 和處理 ActionEvent 事件的接口方法(actionPeformed 等 實現(xiàn)編碼如下 :import javax.swing.* 。import java.awt.* 。import java.awt.event.* 。p

17、ublic class Year extends Box implements ActionListenerint year 。JTextField showYear=null 。JButton 明年 ,去年。CalendarPad 日歷。public Year(CalendarPad 日歷 super(BoxLayout.X_AXIS 。 showYear=new JTextField(4 。 showYear.setForeground(Color.blue 。 showYear.setFont(new Font(TimesRomn,Font.BOLD,14 this. 日歷=日歷。yea

18、r=日歷.getYear(。明年=new JButton(” 下年。去年 =new JButton( 上年。add(去年。add(showYear 。add(明年。showYear.addActionListener(this 。去年 .addActionListener(this 。明年.addActionListener(this 。public void setYear(int yearthis.year=year 。showYear.setText(+year 。public int getYear(return year 。public void actionPerformed(Ac

19、tionEvent eif(e.getSource(= 去年year=year-1 。showYear.setText(+year 。日歷 .setYear(year 。日歷.設置日歷牌(year,日歷.getMonth(。else if(e.getSource(= 明年year=year+1 。 showYear.setText(+year 。 日歷 .setYear(year 。 日歷 .設置日歷牌 (year, 日歷 .getMonth( 。else if(e.getSource(=showYeartryyear=Integer.parseInt(showYear.getText( 。

20、showYear.setText(+year 。 日歷 .setYear(year 。日歷 .設置日歷牌 (year, 日歷 .getMonth( 。 catch(NumberFormatException eeshowYear.setText(+year 。 日歷 .setYear(year 。 日歷 .設置日歷牌 (year, 日歷 .getMonth( 。 3. 日歷記事本系統(tǒng)月設置模塊 (Month.java該模塊用于實現(xiàn)日歷記事本系統(tǒng)中關于月的設置 模塊中包含的主要成員變量有用于改變月的按鈕 (Jbutton 上月 下月,顯 示月的文本框 (JTextField模塊中包含的主要方法有

21、用于設置月的方法 (setMonth, 用于獲取月的方法(getMonth 和處理 ActionEvent 事件的接口方法(actionPeformed 等 實現(xiàn)編碼如下 :import javax.swing.import java.awt.* 。import java.awt.event.* 。public class Month extends Box implements ActionListenerint month 。JTextField showMonth=null 。JButton 下月 ,上月。CalendarPad 日歷。public Month(CalendarPad 日

22、歷 super(BoxLayout.X_AXIS 。this. 日歷=日歷。showMonth=new JTextField(2 。month= 日歷 .getMonth( 。showMonth.setEditable(false 。 showMonth.setForeground(Color.blue 。showMonth.setFont(new Font(TimesRomn,Font.BOLD,16 下月=new JButton(” 下月。上月 =new JButton( 上月 。add( 上月 。add(showMonth 。add( 下月 。上月 .addActionListener(

23、this下月 .addActionListener(this 。 showMonth.setText(+month 。public void setMonth(int monthif(month=1this.month=month 。elsethis.month=1 。showMonth.setText(+month 。public int getMonth(return month 。public void actionPerformed(ActionEvent e if(e.getSource(= 上月 if(month=2month=month-1 。日歷 .setMonth(month

24、 。日歷.設置日歷牌 (日歷 .getYear(,month else if(month=1month=12 。日歷 .setMonth(month 。日歷.設置日歷牌 (日歷 .getYear(,month showMonth.setText(+month 。else if(e.getSource(= 下月 if(monthmonth=month+1 。日歷 .setMonth(month 。日歷.設置日歷牌 (日歷 .getYear(,month 。else if(month=12month=1 。日歷 .setMonth(month 。 日歷.設置日歷牌 (日歷 .getYear(,mo

25、nth 。 showMonth.setText(+month 。4. 日歷記事本系統(tǒng)記事本模塊 (NotePad.java 該模塊中包含的主要成員變量有文本框 (JTextArea, 按鈕 (JButton 保存 日志 刪除日志 ,用于存放日志記錄的文件 (File 以及響應相關操作的信息提示 (JLabel該模塊中包含的主要方法有設置信息條 ,設置文本區(qū) ,獲取日志內(nèi)容 ,保存 日志,刪除日志實現(xiàn)編碼如下 :import java.awt.* 。import java.awt.event.* 。import java.util.* 。import javax.swing.* 。import

26、javax.swing.event.* 。import java.io.* 。public class NotePad extends JPanel implements ActionListenerJTextArea text 。JButton 保存日志 ,刪除日志。Hashtable table 。JLabel 信息條。int year,month,day 。File file 。CalendarPad calendar 。public NotePad(CalendarPad calendarthis.calendar=calendar 。 year=calendar.getYear( 。

27、 month=calendar.getMonth( 。 day=calendar.getDay( 。 table=calendar.getHashtable( 。 file=calendar.getFile( 。信息條=new JLabel(+year+年+month+月+day+日,JLabel.CENTER 。信息條 .setFont(new Font(TimesRoman,Font.BOLD,16 信息條 .setForeground(Color.blue 。text=new JTextArea(10,10 。保存日志 =new JButton( 保存日志 。 刪除日志 =new JBu

28、tton( 刪除日志 。 保存日志 .addActionListener(this 。 刪除日志 .addActionListener(this 。 setLayout(new BorderLayout( 。 JPanel pSouth=new JPanel( 。 add( 信息條 ,BorderLayout.NORTH 。 pSouth.add( 保存日志 。pSouth.add( 刪除日志 。 add(pSouth,BorderLayout.SOUTH 。add(new JScrollPane(text,BorderLayout.CENTER 。public void actionPerf

29、ormed(ActionEvent eif(e.getSource(= 保存日志 保存日志 (year,month,day 。else if(e.getSource(= 刪除日志 刪除日志 (year,month,day 。public void setYear(int yearthis.year=year 。public int getYear(return year 。public void setMonth(int monththis.month=month 。public int getMonth(return month 。public void setDay(int daythis

30、.day=day 。public int getDay(return day 。public void 設置信息條 (int year,int month,int day信息條.setText(+year+年+month+月+day+日。public void 設置文本區(qū) (String stext.setText(s 。public void 獲取日志內(nèi)容 (int year,int month,int dayString key=+year+month+day 。 tryFileInputStream inOne=new FileInputStream(file 。 ObjectInput

31、Stream inTwo=newObjectInputStream(inOne 。 table=(HashtableinTwo.readObject( 。 inOne.close( 。 inTwo.close( 。 catch(Exception ee if(table.containsKey(keyString m=+yea葉年+month+月+day+這一天有日志 記載 ,是否查看 ?。int ok=JOptionPane.showConfirmDialog(this,m, 詢問,JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE

32、 。 if(ok=JOptionPane.YES_OPTIONtext.setText(Stringtable.get(key 。 elsetext.setText( 。elsetext.setText( 無記錄 。public void 保存日志 (int year,int month,int dayString 日志內(nèi)容 =text.getText( 。String key=+year+month+day 。String m=+year+年+month+月+day+保存日志嗎?。 int ok=JOptionPane.showConfirmDialog(this,m, 詢問 ,JOptio

33、nPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE if(ok=JOptionPane.YES_OPTIONtryFileInputStream inOne=new FileInputStream(file 。ObjectInputStream inTwo=new ObjectInputStream(inOne 。table=(HashtableinTwo.readObject( 。 inOne.close( 。inTwo.close( 。 table.put(key, 日志內(nèi)容 。FileOutputStream out=newFileOutpu

34、tStream(file 。ObjectOutputStream objectOut=new ObjectOutputStream(out 。objectOut.writeObject(table 。 objectOut.close( 。out.close( 。catch(Exception eepublic void 刪除日志 (int year,int month,int dayString key=+year+month+day 。if(table.containsKey(keyString m=刪除+year+年+month+月+day+日的日志 嗎?。int ok=JOptionPane.showConfirmDialog(this,m, 詢問 ,JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE 。if(ok=JOptionPane.YES_OPT

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論