Java編寫-萬年歷_第1頁
Java編寫-萬年歷_第2頁
Java編寫-萬年歷_第3頁
Java編寫-萬年歷_第4頁
Java編寫-萬年歷_第5頁
已閱讀5頁,還剩13頁未讀 繼續免費閱讀

下載本文檔

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

文檔簡介

1、師大學遠程教育學院考查課科目 java 程序設計 姓名 霍娟 學號 002專業 計算機科學與技術 批次 161層次 專升本 學習中心 職業技術學院 Java 萬年 歷項目概述 :這個項目是一個簡單的 Java 萬年歷,可以實現所有年份的公歷日期的查詢,并且在相應的日期做備忘錄,以及可以顯示當前的日期以及時間。使用的是 Oracle 數據庫進行連接。二 具體功能介紹 : (1)萬年歷查詢:點擊圖形界面中的上年、下年鍵用來調整要查詢的年份,或 者可以直接在上年下年按鈕直接的文本框中輸入年份(負數表示公元前) ,以回 車結束;點擊上月或者下月來調整要查詢的月份, 然后可以看到這個月的每一天 所對應的

2、星期。( 2) Clock 功能:在萬年歷下面顯示當前的年月日時分秒,相當于一個時鐘的 功能。(3)記事本功能:可以任選某年某月的某一天,單擊,在右側會出現這一天的 備忘錄,如果存在,則顯示某年某月某日有日志記載,是否想看,否則,則在文 本框中顯示無記錄; 然后可以編輯這一天的備忘錄, 編輯好了之后, 點擊保存日 志,彈出對話框某年某月某日保存日志嗎,點擊保存,則日志被保存,反之未被 保存;若想刪除某日的日志,則單擊這一天,然后點擊右側的刪除日志,顯示刪 除某年某月某日的日志嗎,點擊是,則日志被刪除。從文件中讀取備忘錄的容, 用數據庫進行存儲和刪除操作。三 設計與實現 (需要附全部代碼, GU

3、I 自動生成代碼除外) :1 類 的 設 計 ( 繼 承 、 多 態 、 數 據 結 構 ) : 核 心 類 是 Month,Year,NotePad,Clock,DBAccess,CalendarPad(. 其中繼承用粗體,接口用粗 斜體,數據結構是哈希表,用粗下劃線,多態用斜體 +點點短線式下劃線) 2 Java IO (文件訪問):用的是粗體 + 浪線3 JDBC (數據庫訪問):使用 Oracle 數據庫連接,是直連(雙下劃線) 數據庫是: create table mynotes(mydate varchar2(50) primary key,note varchar2(100) n

4、ot null);4 Socket + Multi-Thread:斜體(定義在 Clock 中的 Thread t)5 GUI (用戶界面):點下劃線來表示 GUI 用戶界面6 其他功能:(無)以下是全部代碼(共六個.Java 文件)/對月份的選擇package javaapplication13;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Month extends Box implements ActionListener/ ActionListener 接口int month;JT

5、extField showMonth=null;JButton RMonth,NMonth;CalendarPad cal;public Month(CalendarPad c)super(BoxLayout.X_AXIS);this.cal=c;showMonth=new JTextField(2);month=c.getMonth();showMonth.setEditable(false); showMonth.setForeground(Color.blue);showMonth.setFont(new Font(TimesRomn,Font.BOLD,16);NMonth=new J

6、Button(下月 );RMonth=new JButton(上月 );add(RMonth);add(showMonth);add(NMonth);RMonth.addActionListener(this);NMonth.addActionListener(this); showMonth.setText(+month);public void setMonth(int month)if(month=1)this.month=month;elsethis.month=1;showMonth.setText(+month);public int getMonth()return month;

7、public void actionPerformed(ActionEvent e)if(e.getSource()=RMonth)if(month=2) month=month-1; cal.setMonth(month); cal.setCal(cal.getYear(),month);else if(month=1)month=12;cal.setMonth(month); cal.setCal(cal.getYear(),month); showMonth.setText(+month);else if(e.getSource()=NMonth)if(month|oed李重賈田H Je

8、puaieg/:ius = iuss!屮 (ius luoiuoeislwises piOA siqndl.ius ujn;8j ()iuisg6 luoiuowis Siqnd!sj = sjsiqi (sj esilns8)sji8s piOA siqnd!sj ujn;8j Osygb esiinsoy ojiqnd !uuoo = uuoosiqi (uuoo uo!p8uuoo)uuo9i8S piOA siqnd!uuoo ujn;8j ()uuooi86 uoipauuoo siqnd (e uoiid8OX3-|Os) qoeo !()8S0|0SJ (linu =i sj)

9、jiint year,month,day; Hashtable hashtable;File file;JTextField showDay;JLabel title;JLabel label = new JLabel49;JLabel y_label = new JLabel(年份 );JLabel m_label = new JLabel(月份 );Calendar cal;Calendar now = Calendar.getInstance(); /實 例化 Calendar int week;NotePad notepad=null;Month ChangeMonth;Year Ch

10、angeYear;String w= 星期日 ,星期一 ,星期二 ,星期三,星期四,星期五,星期六 ;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;thi

11、s.month=month; this.day=day;ChangeYear=new Year(this);ChangeYear.setYear(year); ChangeMonth=new Month(this); ChangeMonth.setMonth(month);title=new JLabel7;showDay=new JTextField42;for(int j=0;j7;j+)titlej=new JLabel();titlej.setText(wj);titlej.setBorder(BorderFactory.createRaisedBevelBorder(); leftC

12、enter.add(titlej);title0.setForeground(Color.red); title6.setForeground(Color.blue);for(int i=0;i42;i+) showDayi=new JTextField(); showDayi.addMouseListener(this); showDayi.setEditable(false); leftCenter.add(showDayi);cal=Calendar.getInstance();Box box=Box.createHorizontalBox(); box.add(ChangeYear);

13、 box.add(ChangeMonth); leftNorth.add(box);leftPanel.setLayout(new BorderLayout(); leftPanel.add(leftNorth,BorderLayout.NORTH); leftPanel.add(leftCenter,BorderLayout.CENTER);rightPanel.add(new Label(年份框輸入年份 (負數公元前 ) 回車確定 ), BorderLayout.SOUTH) ;leftPanel.add(new Clock(this),BorderLayout.SOUTH); /調用 C

14、lock 類實 例,來實現對當前時間的顯示leftPanel.validate();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()tryFileOutputStream out=

15、new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(hashtable);objectOut.close(); out.close(); catch(IOException e)notepad=new NotePad(this);rightPanel.add(notepad);setCal(year,month); addWindowListener(new WindowAdapter() public void windowClo

16、sing(WindowEvent e)System.exit(0););setVisible(true);setBounds(100,50,524,285);validate();public void setCal(int year,int month)cal.set(year,month-1,1);week=cal.get(Calendar.DAY_OF_WEEK)-1;if(month=1|month=2|month=3|month=5|month=7 |month=8|month=10|month=12) QueryNum(week,31);else if(month=4|month=

17、6|month=9|month=11)QueryNum(week,30);else if(month=2) if(year%4=0&year%100!=0)|(year%400=0) QueryNum(week,29);elseQueryNum(week,28);public void QueryNum(int w_num,int month_num)for(int i=w_num,n=1;iw_num+month_num;i+) showDayi.setText(+n); if(n=day) showDayi.setForeground(Color.green); showDayi.setF

18、ont(new Font(TimesRoman,Font.BOLD,20);elseshowDayi.setFont(newFont(TimesRoman,Font.BOLD,12); showDayi.setForeground(Color.black);if(i%7=6)showDayi.setForeground(Color.blue);if(i%7=0) showDayi.setForeground(Color.red);n+;for(int i=0;iw_num;i+)showDayi.setText();for(int i=w_num+month_num;i42;i+) showD

19、ayi.setText();public int getYear()return year;public void 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()return file;public void mousePressed(MouseEvent e)JTextField source=(JTextField)e.getSource(); tryday=Integer.parseInt(source.getText(); notepad.setDay(day);notepad.setMesLabel(year,month,day);notepad.setText(null); notepad.get

溫馨提示

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

最新文檔

評論

0/150

提交評論