版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
日歷記事本1.程計的語等語2.計案證2.1計思路2.2計方法
個主類...5CalenderPad.javaNotepad.javaClock.java類CalendarWindowCalendarImageCalenderMessageCalenderPadNotepadClockFileJTextFieldJTextAre2.3能模塊年份變...月份變?nèi)掌谑緢D片示日志示時鐘示保存刪、取志2.4程圖如...開始顯示窗口界面選擇日期保存日志是保存并標(biāo)記有
讀取日志是顯示日志
刪除日志是刪除并去掉有否
否
否結(jié)束程序流2.5、方法屬性說明CalendarWindow類對是對和創(chuàng)...是等創(chuàng)事事)接CalenderMessage類.5.3CalenderPad對(對...Notepad類創(chuàng)是創(chuàng)(CalendarImage類是Clock類包是)3.計果分,為...45......所所......4.計會...5.考獻(xiàn)附:importjavax.swing.*;importjava.io.*;importjava.awt.*;publicclassCalendarImageextendsJPanel{FileimageFile;Imageimage;Toolkittool;CalendarImage(){tool=getToolkit();}publicvoidsetImageFile(Filef){imageFile=f;try{image=tool.getImage(imageFile.toURI().toURL());}catch(Exceptionexp){}repaint();}publicvoidpaintComponent(Graphicsg){...super.paintComponent(g);intw=getBounds().width;inth=getBounds().height;g.drawImage(image,0,0,w,h,this);}}importjava.util.Calendar;publicclassCalendarMessage{intyear=-1,month=-1,day=-1;publicvoidsetYear(intyear){this.year=year;}publicintgetYear(){returnyear;}publicvoidsetMonth(intmonth){if(month<=12&&month>=1)this.month=month;elsethis.month=1;}publicintgetMonth(){returnmonth;}publicvoidsetDay(intday){this.day=day;}publicintgetDay(){returnday;}publicString[]getMonthCalendar(){String[]day=newString[42];Calendarrili=Calendar.getInstance();rili.set(year,month-1,1);//將日歷翻1,注0表示一月...11表示十二月int星期幾=rili.get(Calendar.DAY_OF_WEEK)-1;intdayAmount=0;if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)dayAmount=31;if(month==4||month==6||month==9||month==11)dayAmount=30;...if(month==2)if(((year%4==0)&&(year%100!=0))||(year%400==0))dayAmount=29;elsedayAmount=28;for(inti=0;i<星期幾;i++)day[i]="";for(inti=星期幾,n=1;i<星期幾+dayAmount;i++){day[i]=String.valueOf(n);n++;}for(inti=星期幾+dayAmount;i<42;i++)day[i]="";returnday;}}importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.util.*;publicclassCalendarPadextendsJPanel{intyear,month,day;CalendarMessagecalendarMessage;JTextField[]showDay;JLabeltitle[];String[]星期={"SUN","MON","TUE","WED","THU","FRI","SAT六"};JPanelnorth,center;publicCalendarPad(){setLayout(newBorderLayout());north=newJPanel();north.setLayout(newGridLayout(1,7));center=newJPanel();center.setLayout(newGridLayout(6,7));add(center,BorderLayout.CENTER);add(north,BorderLayout.NORTH);title=newJLabel[7];for(intj=0;j<7;j++){title[j]=newJLabel();title[j].setFont(newFont("TimesRoman",Font.BOLD,12));title[j].setText(星期[j]);title[j].setHorizontalAlignment(JLabel.CENTER);title[j].setBorder(BorderFactory.createRaisedBevelBorder());...north.add(title[j]);}title[0].setForeground(Color.red);title[6].setForeground(Color.blue);}publicvoidsetShowDayTextField(JTextField[]text){showDay=text;for(inti=0;i<showDay.length;i++){showDay[i].setFont(newFont("TimesRoman",Font.BOLD,15));showDay[i].setHorizontalAlignment(JTextField.CENTER);showDay[i].setEditable(false);center.add(showDay[i]);}}publicvoidsetCalendarMessage(CalendarMessagecalendarMessage){this.calendarMessage=calendarMessage;}publicvoidshowMonthCalendar(){String[]a=calendarMessage.getMonthCalendar();for(inti=0;i<42;i++)showDay[i].setText(a[i]);validate();}}importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.util.*;importjava.io.*;publicclassCalendarWindowextendsJFrameimplementsActionListener,MouseListener,FocusListener{JMenuBarmenu;JMenusz;JMenuItemxtx;intyear,month,day;CalendarMessagecalendarMessage;CalendarPadcalendarPad;NotePadnotePad;JTextFieldshowYear,showMonth;JTextField[]showDay;CalendarImagecalendarImage;Clockclock;...JButtonnextYear,previousYear,nextMonth,previousMonth;JButtonbutton0,saveDailyRecord,deleteDailyRecord,readDailyRecord;Filedir;ColorbackColor=Color.white;publicCalendarWindow(){dir=newFile("./dailyRecord");dir.mkdir();showDay=newJTextField[42];for(inti=0;i<showDay.length;i++){showDay[i]=newJTextField();showDay[i].setBackground(backColor);showDay[i].setLayout(newGridLayout(3,3));showDay[i].addMouseListener(this);showDay[i].addFocusListener(this);}calendarMessage=newCalendarMessage();calendarPad=newCalendarPad();notePad=newNotePad();Calendarcalendar=Calendar.getInstance();calendar.setTime(newDate());year=calendar.get(Calendar.YEAR);month=calendar.get(Calendar.MONTH)+1;day=calendar.get(Calendar.DAY_OF_MONTH);calendarMessage.setYear(year);calendarMessage.setMonth(month);calendarMessage.setDay(day);calendarPad.setCalendarMessage(calendarMessage);calendarPad.setShowDayTextField(showDay);notePad.setShowMessage(year,month,day);calendarPad.showMonthCalendar();doMark();//給有日志的做標(biāo)記,見后面的方法calendarImage=newCalendarImage();calendarImage.setImageFile(newFile("01.jpg"));clock=newClock();JSplitPanesplitV1=newJSplitPane(JSplitPane.VERTICAL_SPLIT,calendarPad,calendarImage);JSplitPanesplitV2=newJSplitPane(JSplitPane.VERTICAL_SPLIT,notePad,clock);JSplitPanesplitH=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,splitV1,splitV2);add(splitH,BorderLayout.CENTER);showYear=newJTextField(""+year,6);...showYear.setFont(newFont("TimesRoman",Font.BOLD,12));showYear.setHorizontalAlignment(JTextField.CENTER);showMonth=newJTextField(""+month,4);showMonth.setFont(newFont("TimesRoman",Font.BOLD,12));showMonth.setHorizontalAlignment(JTextField.CENTER);button0=newJButton("圖像");menu=newJMenuBar();sz=newJMenu("設(shè)置");xtx=newJMenuItem("選擇圖像");nextYear=newJButton("下年");previousYear=newJButton("上年");nextMonth=newJButton("下月");previousMonth=newJButton("上月);nextYear.addActionListener(this);previousYear.addActionListener(this);nextMonth.addActionListener(this);previousMonth.addActionListener(this);showYear.addActionListener(this);JPanelnorth=newJPanel();north.add(previousYear);north.add(showYear);north.add(nextYear);north.add(previousMonth);north.add(showMonth);north.add(nextMonth);xtx.addActionListener(this);menu.add(sz);sz.add(xtx);this.setJMenuBar(menu);add(north,BorderLayout.NORTH);saveDailyRecord=newJButton("保存日志);deleteDailyRecord=newJButton("除日志");readDailyRecord=newJButton("讀取日志);saveDailyRecord.addActionListener(this);deleteDailyRecord.addActionListener(this);readDailyRecord.addActionListener(this);JPanelpSouth=newJPanel();pSouth.add(saveDailyRecord);pSouth.add(deleteDailyRecord);pSouth.add(readDailyRecord);add(pSouth,BorderLayout.SOUTH);setVisible(true);setBounds(60,60,660,480);validate();...setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==nextYear){year++;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}elseif(e.getSource()==xtx){FileDialogdia=newFileDialog(this,"選定圖片",FileDialog.LOAD);dia.setModal(true);dia.setVisible(true);if((dia.getDirectory()!=null)&&(dia.getFile()!=null)){calendarImage.setImageFile(newFile(dia.getFile()));}}elseif(e.getSource()==previousYear){year--;showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}elseif(e.getSource()==nextMonth){month++;if(month>12)month=1;showMonth.setText(""+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}elseif(e.getSource()==previousMonth){month--;...if(month<1)month=12;showMonth.setText(""+month);calendarMessage.setMonth(month);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}elseif(e.getSource()==showYear){Strings=showYear.getText().trim();chara[]=s.toCharArray();booleanboo=false;for(inti=0;i<a.length;i++)if(!(Character.isDigit(a[i])))boo=true;if(boo==true)//彈出“警告”消息對話框","警告",JOptionPane.WARNING_MESSAGE);elseif(boo==false)year=Integer.parseInt(s);showYear.setText(""+year);calendarMessage.setYear(year);calendarPad.setCalendarMessage(calendarMessage);calendarPad.showMonthCalendar();notePad.setShowMessage(year,month,day);doMark();}elseif(e.getSource()==saveDailyRecord){notePad.save(dir,year,month,day);doMark();}elseif(e.getSource()==deleteDailyRecord){notePad.delete(dir,year,month,day);doMark();}elseif(e.getSource()==readDailyRecord)notePad.read(dir,year,month,day);}publicvoidmousePressed(MouseEvente){JTextFieldtext=(JTextField)e.getSource();Stringstr=text.getText().trim();try{day=Integer.parseInt(str);...}catch(NumberFormatExceptionexp){}calendarMessage.setDay(day);notePad.setShowMessage(year,month,day);}publicvoidmouseReleased(MouseEvente){}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}publicvoidmouseClicked(MouseEvente){}publicvoidfocusGained(FocusEvente){Component=(Component)e.getSource();.setBackground(Color.pink);}publicvoidfocusLost(FocusEvente){Component=(Component)e.getSource();.setBackground(backColor);}publicvoiddoMark(){for(inti=0;i<showDay.length;i++){showDay[i].removeAll();Stringstr=showDay[i].getText().trim();try{intn=Integer.parseInt(str);if(isHaveDailyRecord(n)==true){//見后面的isHaveDailyRecord()方法JLabelmess=newJLabel("");mess.setFont(newFont("TimesRoman",Font.PLAIN,11));mess.setForeground(Color.blue);showDay[i].add(mess);}}catch(Exceptionexp){}}calendarPad.repaint();calendarPad.validate();}publicbooleanisHaveDailyRecord(intn){Stringkey=""+year+""+month+""+n;String[]dayFile=dir.list();booleanboo=false;for(intk=0;k<dayFile.length;k++){if(dayFile[k].equals(key+".txt")){boo=true;...break;}}returnboo;}publicstaticvoidmain(Stringargs[]){newCalendarWindow();}}importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.awt.geom.*;importjava.util.*;importjava.io.*;.*;importjava.applet.*;publicclassClockextendsJPanelimplementsActionListener{Datedate;javax.swing.TimersecondTime;inthour,munite,second;Line2DsecondLine,muniteLine,hourLine;inta,b,c,width,height;double[]pointSX=newdouble[60],//來表示秒針端點(diǎn)坐標(biāo)的數(shù)組pointSY=newdouble[60],pointMX=newdouble[60],//用來表示分針端點(diǎn)坐標(biāo)的數(shù)組pointMY=newdouble[60],pointHX=newdouble[60],//用來表示時針端點(diǎn)坐標(biāo)的數(shù)組pointHY=newdouble[60];Clock(){setBackground(Color.cyan);initPoint();secondTime=newjavax.swing.Timer(1000,this);secondLine=newLine2D.Double(0,0,0,0);muniteLine=newLine2D.Double(0,0,0,0);hourLine=newLine2D.Double(0,0,0,0);secondTime.start();//針開始計時}privatevoidinitPoint(){width=getBounds().width;height=getBounds().height;pointSX[0]=0;//12秒針位置...pointSY[0]=-height/2*5/6;pointMX[0]=0;//12分針位置pointMY[0]=-(height/2*4/5);pointHX[0]=0;//12時針位置pointHY[0]=-(height/2*2/3);doubleangle=6*Math.PI/180;//度為6度for(inti=0;i<59;i++){//算數(shù)組中的坐標(biāo)pointSX[i+1]=pointSX[i]*Math.cos(angle)-Math.sin(angle)*pointSY[i];pointSY[i+1]=pointSY[i]*Math.cos(angle)+pointSX[i]*Math.sin(angle);pointMX[i+1]=pointMX[i]*Math.cos(angle)-Math.sin(angle)*pointMY[i];pointMY[i+1]=pointMY[i]*Math.cos(angle)+pointMX[i]*Math.sin(angle);pointHX[i+1]=pointHX[i]*Math.cos(angle)-Math.sin(angle)*pointHY[i];pointHY[i+1]=pointHY[i]*Math.cos(angle)+pointHX[i]*Math.sin(angle);}for(inti=0;i<60;i++){pointSX[i]=pointSX[i]+width/2;//標(biāo)平移pointSY[i]=pointSY[i]+height/2;pointMX[i]=pointMX[i]+width/2;//標(biāo)平移pointMY[i]=pointMY[i]+height/2;pointHX[i]=pointHX[i]+width/2;//標(biāo)平移pointHY[i]=pointHY[i]+height/2;}}publicvoidpaintComponent(Graphicsg){super.paintComponent(g);initPoint();for(inti=0;i<60;i++){//繪制表盤上的小刻度和大刻度intm=(int)pointSX[i];intn=(int)pointSY[i];if(i%5==0){if(i==0||i==15||i==30||i==45){intk=10;g.setColor(Color.orange);g.fillOval(m-k/2,n-k/2,k,k);}else{intk=7;g.setColor(Color.orange);...g.fillOval(m-k/2,n-k/2,k,k);}}else{intk=2;g.setColor(Color.black);g.fillOval(m-k/2,n-k/2,k,k);}}g.fillOval(width/2-5,height/2-5,10,10);//表中心的實(shí)心圓Graphics2Dg_2d=(Graphics2D)g;g_2d.setColor(Color.red);g_2d.draw(secondLine);BasicStrokebs=newBasicStroke(2f,BasicStroke.CAP_ROUND,BasicStroke.JOIN_MITER);g_2d.setStroke(bs);g_2d.setColor(Color.blue);g_2d.draw(muniteLine);bs=newBasicStroke(4f,BasicStroke.CAP_BUTT,BasicStroke.JOIN_MITER);g_2d.setStroke(bs);g_2d.setColor(Color.orange);g_2d.draw(hourLine);}publicvoidactionPerformed(ActionEvente){if(e.getSource()==secondTime){date=newDate();Strings=date.toString();hour=Integer.parseInt(s.substring(11,13));munite=Integer.parseInt(s.substring(14,16));second=Integer.parseInt(s.substring(17,19));//取時間中的秒inth=hour%12;=second;//針端點(diǎn)的坐標(biāo)=munite;//針端點(diǎn)的坐標(biāo)c=h*5+munite/12;//針端點(diǎn)的坐標(biāo)secondLine.setLine(width/2,height/2,(int)pointSX[a],(int)pointSY[a]);muniteLine.setLine(width/2,height/2,(int)pointMX[b],(int)pointMY[b]);hourLine.setLine(width/2,height/2,(int)pointHX[c],(int)pointHY[c]);repaint();}...if(second==0){FilemusicFile=newFile("01.wav");try{URIuri=musicFile.toURI();URLurl=uri.toURL();AudioClipclip=Applet.newAudioClip(url);clip.play();}catch(MalformedURLExceptione1){e1.printStackTrace();}}}}importjava.awt.*;importjavax.swing.*;importjava.io.*;importjava.awt.event.*;publicclassNotePadextendsJPanelimplementsActionListener,ItemListener{JTextAreatext;JTextFieldshowMessage;JPopupMenumenu;JMenuItemitemCopy,itemCut,itemPaste,itemClear;intsy;publicJPaneljp;Choicelist1;Choicelist2;Stringsize[]={"10","12","14","16","18","20","24","26","28","30","32"};Stringfonts[]={"常規(guī)","斜體","加粗,"斜體加粗"};publicNotePad(){showMessage=newJTextField();showMessage.setHorizontalAlignment(JTextField.CENTER);showMessage.setFont(newFont("TimesRoman",Font.BOLD,16));showMessage.setForeground(Color.blue);showMessage.setBackground(Color.pink);showMessage.setBorder(BorderFactory.createRaisedBevelBorder());showMessage.setEditable(false);jp=newJPanel();list1=newChoice();...list2=newChoice();for(inti=0;i<size.length;i++){list1.add(size[i]);}for(inti=0;i<fonts.length;i++){list2.add(fonts[i]);}menu=newJPopupMenu();itemCopy=newJMenuItem("復(fù)制");itemCut=newJMenuItem("剪切");itemPaste=newJMenuItem("粘貼");itemClear=newJMenuItem("清空");itemCopy.addActionListener(this);itemCut.addActionListener(this);itemPaste.addActionListener(this);itemClear.addActionListener(this);menu.add(itemCopy);menu.add(itemCut);menu.add(itemPaste);menu.add(itemClear);jp.add(list1);jp.add(list2);text=newJTextArea(10,10);text.addMouseListener(newMouseAdapter(){publicvoidmousePressed(MouseEvente){if(e.getModifiers()==InputEvent.BUTTON3_MASK)menu.show(text,e.getX(),e.getY());}});setLayout(newBorderLayout());Colorc=newColor(208,243,134);text.setBackground(c);add(showMessage,BorderLayout.NORTH);add(newJScrollPane(text),BorderLayout.CENTER);add(jp,BorderLayout.SOUTH);setBounds(0,0,200,200);setVisible(true);list1.addItemListener(this);...list2.addItemListener(this);}publicvoidsetShowMessage(intyear,intmonth,intday){showMessage.setText(""+year+"年+month+"月"+day+"日");}publicvoiditemStateChanged(ItemEvente){Stringn1=list1.getSelectedItem();Stringstyle=list2.getSelectedItem();intn2=Integer.parseInt(n1);if(style.equals("常規(guī)")){sy=Font.PLAIN;}elseif(style.equals("斜體")){sy=Font.ITALIC;}elseif(style.equals("加粗")){sy=Font.BOLD;}else{sy=Font.BOLD+Font.ITALIC;}Fontf=newFont("TimesRoman",sy,n2);text.setFont(f);}publicvoidsave(Filedir,intyear,intmonth,intday){StringdailyContent=text.getText();StringfileName=""+year+""+month+""+day+".txt";Stringkey=""+year+""+month+""+day;String[]dayFile=dir.list();booleanboo=false;for(intk=0;k<dayFile.length;k++){if(dayFile[k].startsWith(key)){boo=true;break;}}if(boo){Stringm=""+year+"+month+"月"+day+"有日志將新的容添加到日志嗎?";intok=JOptionPane.showConfirmDialog(this,m,"詢問",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);...if(ok==JOptionPane.YES_OPTION){try{Filef=newFile(dir,fileName);RandomAccessFileout=newRandomAccessFile(f,"rw");longfileEnd=out.length();byte[]bb=dailyContent.getBytes();out.seek(fileEnd);out.write(bb);out.close();}catch(IOExceptionexp){}}}else{String沒有日志,存日志嗎?";intok=JOptionPane.showConfirmDialog(this,m,"詢問",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){try{Filef=newFile(dir,fileName);RandomAccessFileout=newR
溫馨提示
- 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)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 電子管特性測試儀市場分析及投資價值研究報告
- 醫(yī)用支撐連褲襪產(chǎn)業(yè)鏈招商引資的調(diào)研報告
- 電話耳機(jī)產(chǎn)品供應(yīng)鏈分析
- 江蘇省徐州市邳州市2023-2024學(xué)年八年級上學(xué)期期中地理試卷(含答案解析)
- 抗震綜合防災(zāi)與校舍安全
- 2024年阜陽市部分醫(yī)院招聘勞務(wù)派遣34人筆試模擬試題及答案解析
- 2024年10月浙江嘉興市海寧市中心醫(yī)院醫(yī)療集團(tuán)編外崗位合同制人員招聘6人筆試模擬試題及答案解析
- 多元文化藝術(shù)活動的實(shí)施計劃
- 制定倉庫環(huán)境保護(hù)的工作措施計劃
- 班級交流活動的多樣化安排計劃
- 2.2--金風(fēng)1.5兆瓦風(fēng)力發(fā)電機(jī)組測量傳感器與模塊
- 零星用工單(派工單)
- 關(guān)于初中英語學(xué)習(xí)的調(diào)查問卷
- 慢性阻塞性肺疾病臨床路徑
- 可研收費(fèi)標(biāo)準(zhǔn)[1999]1283號文
- 人身保險產(chǎn)品條款部分條目示范寫法規(guī)定
- CT的基本結(jié)構(gòu)和成像原理
- 《農(nóng)村集體經(jīng)濟(jì)組織會計》考試試卷
- 《晴天》歌詞精編版
- 防滲漏、防裂縫施工技術(shù)交底.doc
- 城市地下管線普查與實(shí)施方案(完整版)
評論
0/150
提交評論