Java編寫-萬年歷_第1頁
Java編寫-萬年歷_第2頁
Java編寫-萬年歷_第3頁
Java編寫-萬年歷_第4頁
Java編寫-萬年歷_第5頁
已閱讀5頁,還剩13頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

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

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

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

4、ot null);4 Socket + Multi-Thread:斜體(定義在 Clock 中的 Thread t)5 GUI (用戶界面):點(diǎn)下劃線來表示 GUI 用戶界面6 其他功能:(無)以下是全部代碼(共六個(gè).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(); /實(shí) 例化 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)/構(gòu)/ 造函數(shù)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(年份框輸入年份 (負(fù)數(shù)公元前 ) 回車確定 ), BorderLayout.SOUTH) ;leftPanel.add(new Clock(this),BorderLayout.SOUTH); /調(diào)用 C

14、lock 類實(shí) 例,來實(shí)現(xiàn)對當(dāng)前時(shí)間的顯示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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論