![[精品論文]JAVA萬年歷_第1頁](http://file.renrendoc.com/FileRoot1/2019-7/13/aae767bb-8b4e-4582-91d2-fb56368813b7/aae767bb-8b4e-4582-91d2-fb56368813b71.gif)
![[精品論文]JAVA萬年歷_第2頁](http://file.renrendoc.com/FileRoot1/2019-7/13/aae767bb-8b4e-4582-91d2-fb56368813b7/aae767bb-8b4e-4582-91d2-fb56368813b72.gif)
![[精品論文]JAVA萬年歷_第3頁](http://file.renrendoc.com/FileRoot1/2019-7/13/aae767bb-8b4e-4582-91d2-fb56368813b7/aae767bb-8b4e-4582-91d2-fb56368813b73.gif)
![[精品論文]JAVA萬年歷_第4頁](http://file.renrendoc.com/FileRoot1/2019-7/13/aae767bb-8b4e-4582-91d2-fb56368813b7/aae767bb-8b4e-4582-91d2-fb56368813b74.gif)
![[精品論文]JAVA萬年歷_第5頁](http://file.renrendoc.com/FileRoot1/2019-7/13/aae767bb-8b4e-4582-91d2-fb56368813b7/aae767bb-8b4e-4582-91d2-fb56368813b75.gif)
已閱讀5頁,還剩16頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
畢業(yè)設(shè)計課程定做 QQ1714879127Java萬年歷一 項目概述:這個項目是一個簡單的Java萬年歷,可以實現(xiàn)所有年份的公歷日期的查詢,并且在相應(yīng)的日期做備忘錄,以及可以顯示當(dāng)前的日期以及時間。使用的是Oracle數(shù)據(jù)庫進(jìn)行連接。 二 具體功能介紹:(1)萬年歷查詢:點擊圖形界面中的上年、下年鍵用來調(diào)整要查詢的年份,或者可以直接在上年下年按鈕直接的文本框中輸入年份(負(fù)數(shù)表示公元前),以回車結(jié)束;點擊上月或者下月來調(diào)整要查詢的月份,然后可以看到這個月的每一天所對應(yīng)的星期。(2)Clock功能:在萬年歷下面顯示當(dāng)前的年月日時分秒,相當(dāng)于一個時鐘的功能。(3)記事本功能:可以任選某年某月的某一天,單擊,在右側(cè)會出現(xiàn)這一天的備忘錄,如果存在,則顯示某年某月某日有日志記載,是否想看,否則,則在文本框中顯示無記錄;然后可以編輯這一天的備忘錄,編輯好了之后,點擊保存日志,彈出對話框某年某月某日保存日志嗎,點擊保存,則日志被保存,反之未被保存;若想刪除某日的日志,則單擊這一天,然后點擊右側(cè)的刪除日志,顯示刪除某年某月某日的日志嗎,點擊是,則日志被刪除。從文件中讀取備忘錄的內(nèi)容,用數(shù)據(jù)庫進(jìn)行存儲和刪除操作。三 設(shè)計與實現(xiàn)(需要附全部代碼,GUI自動生成代碼除外):1 類的設(shè)計(繼承、多態(tài)、數(shù)據(jù)結(jié)構(gòu)):核心類是Month,Year,NotePad,Clock,DBAccess,CalendarPad.(其中繼承用粗體,接口用粗斜體,數(shù)據(jù)結(jié)構(gòu)是哈希表,用粗下劃線,多態(tài)用斜體+點點短線式下劃線)2 Java IO (文件訪問):用的是粗體+浪線3 JDBC (數(shù)據(jù)庫訪問):使用Oracle數(shù)據(jù)庫連接,是直連(雙下劃線)數(shù)據(jù)庫是:create table mynotes( mydate varchar2(50) primary key, note varchar2(100) not 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; JTextField 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 JButton(下月);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; else this.month=1; showMonth.setText(+month); public int getMonth() return month; 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(month12) month=month+1; cal.setMonth(month); cal.setCal(cal.getYear(),month); else if(month=12) month=1; cal.setMonth(month); cal.setCal(cal.getYear(),month); showMonth.setText(+month); /對年分的選擇package javaapplication13;import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Year extends Box implements ActionListener/ActionListener接口 int year; JTextField showYear=null;JButton NYear,RYear; CalendarPad cal; public Year(CalendarPad c) super(BoxLayout.X_AXIS); showYear=new JTextField(4);showYear.setForeground(Color.blue);showYear.setFont(new Font(TimesRomn,Font.BOLD,14); this.cal=c; year=cal.getYear(); NYear=new JButton(下年);RYear=new JButton(上年); add(RYear); add(showYear); add(NYear); showYear.addActionListener(this); RYear.addActionListener(this); NYear.addActionListener(this); public void setYear(int year) this.year=year; showYear.setText(+year); public int getYear() return year; public void actionPerformed(ActionEvent e) if(e.getSource()=RYear) year=year-1; showYear.setText(+year); cal.setYear(year); cal.setCal(year,cal.getMonth(); else if(e.getSource()=NYear) year=year+1; showYear.setText(+year); cal.setYear(year); cal.setCal(year,cal.getMonth(); else if(e.getSource()=showYear) try year=Integer.parseInt(showYear.getText(); showYear.setText(+year); cal.setYear(year); cal.setCal(year,cal.getMonth(); catch(NumberFormatException ee) showYear.setText(+year); cal.setYear(year); cal.setCal(year,cal.getMonth(); /對備忘錄的操作package javaapplication13;import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;public class NotePad extends JPanel implements ActionListener JTextArea text;JButton save_log,del_log; Hashtable table; JLabel mes_label; int year,month,day; File file; CalendarPad calendar; public NotePad(CalendarPad calendar)/構(gòu)造函數(shù) this.calendar=calendar; Calendar now = Calendar.getInstance(); int hour=now.get(Calendar.HOUR); int minute=now.get(Calendar.MINUTE); year=calendar.getYear(); month=calendar.getMonth(); day=calendar.getDay(); table=calendar.getHashtable(); file=calendar.getFile(); mes_label=new JLabel(+year+年+month+月+day+日+ +hour+:+minute,JLabel.CENTER);mes_label.setFont(new Font(TimesRoman,Font.BOLD,16);mes_label.setForeground(Color.MAGENTA);text=new JTextArea(10,8);save_log=new JButton(保存日志) ;del_log=new JButton(刪除日志) ; save_log.addActionListener(this); del_log.addActionListener(this); setLayout(new BorderLayout(); JPanel pSouth=new JPanel();add(mes_label,BorderLayout.NORTH);pSouth.add(save_log);pSouth.add(del_log);add(pSouth,BorderLayout.SOUTH);add(new JScrollPane(text),BorderLayout.CENTER); public void actionPerformed(ActionEvent e) if(e.getSource()=save_log) saveLog(year,month,day); else if(e.getSource()=del_log) delLog(year,month,day); public void setYear(int year) this.year=year; public int getYear() return year; public void setMonth(int month) this.month=month; public int getMonth() return month; public void setDay(int day) this.day=day; public int getDay() return day; public void setMesLabel(int year,int month,int day) mes_label.setText(+year+年+month+月+day+日); public void setText(String s) text.setText(s); public void getLog(int year,int month,int day) String key=+year+month+day; try FileInputStream inOne=new FileInputStream(file);ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(table.containsKey(key) 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(String)table.get(key); else text.setText(); else text.setText(無記錄); public void saveLog(int year,int month,int day) String 日志內(nèi)容=text.getText(); String key=+year+month+day; String m=+year+年+month+月+day+保存日志嗎?; int ok=JOptionPane.showConfirmDialog(this,m,詢問,JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) try FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.put(key,日志內(nèi)容); FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); catch(Exception ee) /向數(shù)據(jù)庫中添加數(shù)據(jù)。先查詢數(shù)據(jù)庫,判斷是否已有該日記錄,若有則更新,否則插入 DBAccess db = new DBAccess(); if(db.createConn() String testSql = select * from mynotes where mydate=+key+; db.query(testSql); if (db.next() String updatesql = update mynotes set note= + 日志內(nèi)容 + where mydate= + key +; try updatesql = new String(updatesql.getBytes(ISO8859-1), UTF-8); catch (Exception e) e.printStackTrace(); db.closeRs(); db.closeStm(); db.closeConn(); return; db.closeRs(); / 組合新增SQL String sql = insert into mynotes (mydate, note) ; sql += values( + key + ,+日志內(nèi)容 + ); / 轉(zhuǎn)換參數(shù)編碼 try sql = new String(sql.getBytes(ISO8859-1), UTF-8); catch (Exception e) e.printStackTrace(); /*/ 執(zhí)行插入 db.update(sql); db.closeStm(); db.closeConn(); public void delLog(int year,int month,int day) String key=+year+month+day; if(table.containsKey(key) String m=刪除+year+年+month+月+day+日的日志嗎?; int ok=JOptionPane.showConfirmDialog(this,m,詢問,JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) try FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.remove(key); FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); text.setText(null); catch(Exception ee) else String m=+year+年+month+月+day+無日志記錄; JOptionPane.showMessageDialog(this,m,提示,JOptionPane.WARNING_MESSAGE); /刪除數(shù)據(jù)庫記錄 DBAccess db = new DBAccess(); if(db.createConn() / 根據(jù)name組成刪除SQL,執(zhí)行刪除 String sql = delete from mynotes where mydate= +key+; db.update(sql); db.closeStm(); db.closeConn(); /提取當(dāng)前的年月日時分秒,時鐘package javaapplication13;import java.awt.Canvas;import java.awt.Color;import java.awt.Font;import java.awt.Graphics;import java.text.SimpleDateFormat;import java.util.Calendar;class Clock extends Canvas implements Runnable private static final long serialVersionUID = 3660124045489727166L; CalendarPad mf;Thread t;/Multi-Thread(斜體)String time; public Clock(CalendarPad mf) this.mf=mf; setSize(280,40); setBackground(Color.white); t=new Thread(this); /實例化線程 t.start(); /調(diào)用線程 public void run() while(true) try Thread.sleep(1000); /休眠1秒鐘 catch(InterruptedException e) System.out.println(異常); this.repaint(100); /重畫屏幕 /*public abstract void drawString(AttributedCharacterIterator iterator, int x, int y)依據(jù) TextAttribute 類的規(guī)范應(yīng)用指定迭代器的屬性,呈現(xiàn)迭代器的文本。最左側(cè)字符的基線位于此圖形上下文坐標(biāo)系的 (x, y) 位置處。 */對paint函數(shù)進(jìn)行重寫(多態(tài)) public void paint(Graphics g) Font f=new Font(宋體,Font.BOLD,16); SimpleDateFormat SDF=new SimpleDateFormat( yyyy年MM月dd日HH:mm:ss);/格式化時間顯示類型 Calendar now=Calendar.getInstance(); time=SDF.format(now.getTime(); /得到當(dāng)前日期和時間 g.setFont(f); g.setColor(Color.RED); g.drawString(time,25,25); /用Oracle的方式連接數(shù)據(jù)庫package javaapplication13;import java.sql.Connection;import java.sql.DriverManager;import java.sql.ResultSet;import java.sql.SQLException;import java.sql.Statement;/JDBC 數(shù)據(jù)庫連接,直連,利用Oracle(雙下劃線)public class DBAccess public static String drv = oracle.jdbc.driver.OracleDriver;public static String url = jdbc:oracle:thin:localhost:1521:orcl;public static String usr = scott;public static String pwd = helloneal;private Connection conn = null;private Statement stm = null;private ResultSet rs = null;public boolean createConn() boolean b = false;try Class.forName(drv).newInstance();conn = DriverManager.getConnection(url, usr, pwd);b = true; catch (SQLException e) catch (ClassNotFoundException e) catch (InstantiationException e) catch (IllegalAccessException e) return b;public boolean update(String sql) boolean b = false;try stm = conn.createStatement();stm.execute(sql);b = true; catch (Exception e) System.out.println(e.toString();return b;public void query(String sql) try stm = conn.createStatement();rs = stm.executeQuery(sql); catch (Exception e) public boolean next() boolean b = false;try if(rs.next()b = true; catch (Exception e) return b;public String getValue(String field) String value = ;try if(rs!=null)value = rs.getString(field); catch (Exception e) e.printStackTrace();if (value = null) value = ;return value;public void closeConn() try if (conn != null)conn.close(); catch (SQLException e) public void closeStm() try if (stm != null)stm.close(); catch (SQLException e) public void closeRs() try if (rs != null)rs.close(); catch (SQLException e) public Connection getConn() return conn;public void setConn(Connection conn) this.conn = conn;public ResultSet getRs() return rs;public void setRs(ResultSet rs) this.rs = rs;public Statement getStm() return stm;public void setStm(Statement stm) this.stm = stm;/Calendar日歷記事本package javaapplication13;import java.util.Calendar;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;/文件訪問(Java IO)粗體+波浪線import java.util.Hashtable;/哈希表 粗下劃線public class CalendarPad extends JFrame implements MouseListener int 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 ChangeYear; 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;this.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(); leftCenter.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); box.add(ChangeMonth); leftNorth.add(box); leftPanel.setLayout(new BorderLayout(); leftPanel.add(leftNorth,Border
溫馨提示
- 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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 年產(chǎn)5000噸亞磷酸二甲酯、20000噸雙甘膦技改新增可行性分析報告
- 2025年光子美容工作站行業(yè)深度研究分析報告
- 親子情商培養(yǎng)活動策劃
- 烤肉運營方案
- 中國數(shù)碼印花墨水項目創(chuàng)業(yè)投資方案
- 深海探測電池更換與科研保障協(xié)議
- 奧美互動活動創(chuàng)意策劃書3
- 2025年重熔用普通鋁錠項目投資可行性研究分析報告
- 人工智能在客戶服務(wù)行業(yè)的創(chuàng)業(yè)計劃書
- 果蔬可行性研究報告范文
- 《中國潰瘍性結(jié)腸炎診治指南(2023年)》解讀
- 數(shù)字貨幣MASK發(fā)行機(jī)制收益制度解讀課件
- 2023年BIM工程師繼續(xù)教育題庫含答案【b卷】
- 20章-過渡金屬(Ⅰ)-鈦釩鉻錳講解課件
- 吹膜機(jī)技術(shù)和使用說明
- 幼兒園繪本故事:《小熊不刷牙》 課件
- 物質(zhì)安全數(shù)據(jù)表(MSDS)(車用尿素溶液)
- 華北電力大學(xué)ppt模板
- 清朝治理新疆地區(qū)系統(tǒng)性治理課件(16ppt+視頻)2022年新疆地方史讀本(中學(xué)版)
- 員工分紅合作協(xié)議書54559
- 國家自然科學(xué)基金項目評審打分表.xls
評論
0/150
提交評論