java課程設(shè)計簡單日歷程序_第1頁
java課程設(shè)計簡單日歷程序_第2頁
java課程設(shè)計簡單日歷程序_第3頁
java課程設(shè)計簡單日歷程序_第4頁
java課程設(shè)計簡單日歷程序_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

課程設(shè)計題目題目說明經(jīng)過編寫一個鑒于JAVA的應用系統(tǒng)綜合實例,自定義一個日歷組件顯示日期和時間并進行適合的功能擴大,實踐Java語言編程技術(shù)。系統(tǒng)設(shè)計2.1設(shè)計目標一個完好的程序應擁有以下功能:1)顯示當月日歷、目前日期、目前時間;2)可查尋隨意月以及隨意年的日歷;3)使用圖形化界面可以彈出對話框;5)正常退出程序。2.2設(shè)計思想設(shè)計一個類用來組成日歷系統(tǒng)的主窗口,而后編寫一個框架類顯示時間和提示信息。在設(shè)計中應用了多種容器和控件。2.3系統(tǒng)模塊區(qū)分publicstaticclassCalendarTable(日歷類)publicclassMyCalendarpublicstaticvoidmain(String[]extendsJAppletargs)(主日歷框架類)publicstaticclassRollbyJFrame(轉(zhuǎn)動時間類)圖1:簡略日歷的程序構(gòu)造圖初始化:publicvoidinit()達成界面初始化,形成一個以掛歷形式顯示目前日期的窗口。日歷描繪:(1)publicvoidupdateView()改變?nèi)掌诤筮_成更新界面;2)獲得系統(tǒng)日期并傳達日期數(shù)據(jù)并且在人工改變?nèi)掌诤蟮贸霎斎帐侵軒祝?)publicstaticvoidmain(String[]args)主函數(shù)達成系統(tǒng)各算法的調(diào)用并對主窗口的一些屬性進行設(shè)置;轉(zhuǎn)動時間:將時間以文本的形式在文本框中轉(zhuǎn)動播出,并能改變轉(zhuǎn)動的速度。使用類及接口只是簡單說明類的功能,詳盡資料請參看《JavaTM2PlatformStandardEd.6》的電子文檔,慣例的接口與包則省略不屑。以下是日歷程序塊中使用的類packagefancy;importjava.awt.*;importjava.util.*;//主要用此包中的日期和時間類importjavax.swing.*;以下是對轉(zhuǎn)動時間程序塊所使用的類和接口,用到準時器類Timer、用于監(jiān)聽鼠標單擊(焦點改變)事件用于響應鼠標單擊(焦點改變)事件、讓用戶從一個有序序列中選擇一個數(shù)字或許一個對象值的單行輸入字段。//在指準時間間隔觸發(fā)一個或多個

ActionEvent,

創(chuàng)立一個

Timer

對象,在該對象上注冊一個或多個動作偵聽器,以及使用該計時器。并配合事件監(jiān)聽器支持時間的轉(zhuǎn)動播放。5.運轉(zhuǎn)結(jié)果與剖析

start

方法啟動圖2:初始界面顯示日歷。圖3:點擊查察時間按鈕,彈出時間信息對話框。圖4:轉(zhuǎn)動顯示目前時間。程序源代碼/**@(#)MyCalendar.java@authorfancy*/日歷使用的類日歷publicclassMyCalendarextendsJApplet{publicstaticfinalStringWEEK_SUN="SUN";publicstaticfinalStringWEEK_MON="MON";publicstaticfinalStringWEEK_TUE="TUE";publicstaticfinalStringWEEK_WED="WED";publicstaticfinalStringWEEK_THU="THU";publicstaticfinalStringWEEK_FRI="FRI";publicstaticfinalStringWEEK_SAT="SAT";publicstaticfinalColorbackground=Color.yellow;publicstaticfinalColorforeground=Color.black;publicstaticfinalColorheaderBackground=Color.blue;publicstaticfinalColorheaderForeground=Color.white;publicstaticfinalColorselectedBackground=Color.blue;publicstaticfinalColorselectedForeground=Color.white;privateJPanelcPane;privateJLabelyearsLabel;privateJSpinneryearsSpinner;privateJLabelmonthsLabel;privateJComboBoxmonthsComboBox;privateJTabledaysTable;privateAbstractTableModeldaysModel;privateCalendarcalendar;privateJButtonbutton1;publicMyCalendar(){cPane=(JPanel)getContentPane();}publicvoidinit(){cPane.setLayout(newBorderLayout());calendar=Calendar.getInstance();calendar=Calendar.getInstance();JButtonbutton1=newJButton("單擊此處查察時間");button1.setBounds(10,10,10,10);cPane.add(button1,BorderLayout.SOUTH);button1.addActionListener({publicvoidactionPerformed(ActionEvente){RollbyJFramemyrili=newRollbyJFrame();JOptionPane.showMessageDialog(null,"您點擊了"+e.getActionCommand().toString()+"按鈕");}});yearsLabel=newJLabel("Year:");yearsSpinner=newJSpinner();yearsSpinner.setEditor(newJSpinner.NumberEditor(yearsSpinner,"0000"));yearsSpinner.setValue(newInteger(calendar.get(Calendar.YEAR)));yearsSpinner.addChangeListener(newChangeListener(){publicvoidstateChanged(ChangeEventchangeEvent){intdaycalendar.get(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH,1);calendar.set(Calendar.YEAR,yearsSpinner.getValue()).intValue());

((Integer)

=intmaxDaycalendar.getActualMaximum(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH,

day

=>maxDay?maxDay:day);updateView();}});JPanelyearMonthPanel=newJPanel();cPane.add(yearMonthPanel,BorderLayout.NORTH);yearMonthPanel.setLayout(newBorderLayout());yearMonthPanel.add(newJPanel(),BorderLayout.CENTER);JPanelyearPanel=newJPanel();yearMonthPanel.add(yearPanel,BorderLayout.WEST);yearPanel.setLayout(newBorderLayout());yearPanel.add(yearsLabel,BorderLayout.WEST);yearPanel.add(yearsSpinner,BorderLayout.CENTER);monthsLabel=newJLabel("Month:");monthsComboBox=newJComboBox();for(inti=1;i<=12;i++){monthsComboBox.addItem(newInteger(i));}monthsComboBox.setSelectedIndex(calendar.get(Calendar.MONTH));monthsComboBox.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEventactionEvent){intdaycalendar.get(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH,1);calendar.set(Calendar.MONTH,monthsComboBox.getSelectedIndex());intmaxDaycalendar.getActualMaximum(Calendar.DAY_OF_MONTH);calendar.set(Calendar.DAY_OF_MONTH,daymaxDay?maxDay:day);

==>updateView();}});JPanelmonthPanel=newJPanel();yearMonthPanel.add(monthPanel,BorderLayout.EAST);monthPanel.setLayout(newBorderLayout());monthPanel.add(monthsLabel,BorderLayout.WEST);monthPanel.add(monthsComboBox,BorderLayout.CENTER);daysModel=newAbstractTableModel(){publicintgetRowCount(){return9;}publicintgetColumnCount(){return7;}publicObjectgetValueAt(introw,intcolumn){if(row==0){returngetHeader(column);}row--;calendar.set(Calendar.DAY_OF_MONTH,1);intdayCount=calendar.getActualMaximum(Calendar.DAY_OF_MONTH);intmoreDayCount=calendar.get(Calendar.DAY_OF_WEEK)-1;intindex=row*7+column;intdayIndex=index-moreDayCount+1;if(index<moreDayCount||dayIndex>dayCount){returnnull;}else{returnnewInteger(dayIndex);}}};daysTable=newCalendarTable(daysModel,calendar);daysTable.setCellSelectionEnabled(true);daysTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);daysTable.setDefaultRenderer(daysTable.getColumnClass(0),newTableCellRenderer(){publicComponentgetTableCellRendererComponent(JTabletable,Objectvalue,booleanisSelected,booleanhasFocus,introw,intcolumn){Stringtext=(value==null)?"":value.toString();JLabelcell=newJLabel(text);cell.setOpaque(true);if(row==0){cell.setForeground(headerForeground);cell.setBackground(headerBackground);}else{if(isSelected){cell.setForeground(selectedForeground);cell.setBackground(selectedBackground);}else{cell.setForeground(foreground);cell.setBackground(background);}}returncell;}});updateView();cPane.add(daysTable,BorderLayout.CENTER);}publicstaticStringgetHeader(intindex){switch(index){case0:returnWEEK_SUN;case1:returnWEEK_MON;case2:returnWEEK_TUE;case3:returnWEEK_WED;case4:returnWEEK_THU;case5:returnWEEK_FRI;case6:returnWEEK_SAT;default:returnnull;}}publicvoidupdateView(){daysModel.fireTableDataChanged();daysTable.setRowSelectionInterval(calendar.get(Calendar.WEEK_OF_MONTH),calendar.get(Calendar.WEEK_OF_MONTH));daysTable.setColumnSelectionInterval(calendar.get(Calendar.DAY_OF_WEEK)-1,calendar.get(Calendar.DAY_OF_WEEK)-1);}publicstaticclassCalendarTableextendsJTable{privateCalendarcalendar;publicCalendarTable(TableModelmodel,Calendarcalendar){super(model);this.calendar=calendar;}publicvoidchangeSelection(introw,intcolumn,booleantoggle,booleanextend){super.changeSelection(row,column,toggle,extend);if(row==0){return;}Objectobj=getValueAt(row,column);if(obj!=null){calendar.set(Calendar.DAY_OF_MONTH,((Integer)obj).intValue());}}}publicstaticvoidmain(String[]args){JFrameframe=newJFrame("簡略時間日歷");frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);MyCalendarmyCalendar=newMyCalendar();myCalendar.init();frame.getContentPane().add(myCalendar);frame.setLocation(330,80);frame.setSize(360,212);frame.setVisible(true);}轉(zhuǎn)動字publicstaticclassRollbyJFrameextendsJFrame{privateJTextFieldtext;privateJSpinnerspinner;privateTimertimer;privateJButtonbutton;publicRollbyJFrame(){super("轉(zhuǎn)動時間");this.setSize(360,100);this.setLocation(700,120);Containerc=getContentPane();JButtonbutton=newJButton("改正速度");this.add(button,"East");button.addActionListener(this);Calendarnow=Calendar.getInstance();inthour=now.get(Calendar.HOUR);intminute=now.get(Calendar.MINUTE);intyear=now.get(Calendar.YEAR);intmonth=now.get(Calendar.MONTH);intday=now.get(Calendar.DAY_OF_MONTH);text=newJTextField("Hello目前時間是:"+hour+":"+minute+""+year+"/"+month+"/"+day);this.add(text,"Center");text.addFocusListener(this)

溫馨提示

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

評論

0/150

提交評論