java程序设计报告万历.docx

上传人:doc321 文档编号:12825798 上传时间:2021-12-06 格式:DOCX 页数:18 大小:101.64KB
返回 下载 相关 举报
java程序设计报告万历.docx_第1页
第1页 / 共18页
java程序设计报告万历.docx_第2页
第2页 / 共18页
java程序设计报告万历.docx_第3页
第3页 / 共18页
java程序设计报告万历.docx_第4页
第4页 / 共18页
亲,该文档总共18页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《java程序设计报告万历.docx》由会员分享,可在线阅读,更多相关《java程序设计报告万历.docx(18页珍藏版)》请在三一文库上搜索。

1、程序设计报告JAVA 设计报告 2:万年历姓名:王颖学号:学习中心:延安富县学习中心专业:计算机科学与技术层次:专升本身份证号:联系电话:1/18万年历程序设计一、设计分析万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展,我们已经可以通过计算机制作出精美的万年历,通过计算机制作得万年历不但外观美观,而且功能强大。通过万年历,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便。开始二、程序流程框图初始化读、写日期、时间分离日期时间 显示子程序定时子程序日期、时间修改子程序农历自动更新子程序闰月子程返回主

2、程序流程图2/18三、具体设计1、变量设计表 2变量表成员变量描述年、月、日下一年,下一月开始的时间选择月,天改变年改变月前一月,前一年判断是否改变左、又面板年、月左上角信息标签显示月、年标签空格标签右上部时间标变量类型intIntIntStringIntIntIntbooleanJPanelJLabelJLabelJLabelJLabelJLabelJLabelJComboBoxJButtonJButtonJButton3/18名称Year、month、dayYearafterquery,monthafterqueystartdaySwitchMonth ,key,dayChangeyear

3、messagechangemonthmessagepriormonth,prioryearischange, ischange_priornextLeftPane,RightPaneYearLabel,MonthLabelAskShowDateBlankNorthMonthDayYearTopBarTitleMonthComboboxQuerySouthSave,SouthDelete签JTextArea星期标签数组String月份下拉列表JTextField时间确定按钮JTextField保存、删除按钮前、下一月按钮文本区星期字符串数组显示天的文本区输入年的文本区2、程序源代码。public

4、 class calendar extends JFrame implements ActionListener,MouseListener int year,month,day 。int yearafterquery,monthafterquery 。int startday。String SwitchMonth 。String key 。int changeyearmessage。int changemonthmessage。int priormonth 。int prioryear 。boolean ischange=false。boolean ischange_priornext=fa

5、lse 。 private JPanel LeftPane,RightPane。 /Left subprivate JLabel YearLabel 。private JLabel MonthLabel 。PriorMonth ,NextMonthCenterTextweekShowDaysYearText4/18private JComboBox MonthCombobox 。private JTextField ShowDays= new JTextField42。private JTextField YearText 。private JLabel Ask 。private JLabel

6、 ShowDate 。private JLabel Blank 。private JLabel TopBarTitle=new JLabel7。private JButton ToToday 。private JButton Query 。privateString week="SUN","MON","TUE","WED","THU","FRI","SAT"。/right subprivate JLabel NorthMonthDayYear 。priva

7、te JTextArea CenterText 。private JButton SouthSave,SouthDelete 。private JButton PriorMonth 。private JButton NextMonth 。public calendar(int year,int month,int day)setTitle("My Calendar&Textbook")。/the layout about left of jpaneLeftPane = new JPanel() 。JPanel LeftCenter = new JPanel() 。J

8、Panel LeftNorth = new JPanel() 。/JPanel LeftSouth = new JPanel() 。LeftPane.setLayout(new BorderLayout() 。LeftPane.add(LeftNorth,BorderLayout.NORTH)。LeftPane.add(LeftCenter,BorderLayout.CENTER)。LeftPane.add(ToToday=newJButton("Gototoday",newImageIcon("./images/Handle.gif"),BorderL

9、ayout.SOUTH)。ToToday.setBackground(Color.cyan) 。ToToday.addActionListener(this) 。LeftPane.validate() 。/the layout of LeftPane/LeftPane_NorthLeftNorth.setLayout(new GridLayout(3,1,0,-2)。LeftNorth.add(Ask = new JLabel(" Plese input the informations which you want query:")。JPanel North = new

10、JPanel(new FlowLayout(0,8,0) 。LeftNorth.add(North) 。North.add(YearLabel=new JLabel("Year:") 。North.add(YearText = new JTextField(4) 。YearText.setBackground(Color.getHSBColor(30,20,50) 。YearText.setForeground(Color.blue) 。YearText.setFont(new Font("TimesRoman",Font.BOLD,17)。YearTe

11、xt.addActionListener(this) 。5/18YearText.setFocusable(true)。North.add(Blank=new JLabel(" ")。North.add(MonthLabel = new JLabel("Month:")。North.add(MonthCombobox = new JComboBox()。/add month to monthcomboboxfor(int i=1 。 i<=12 。 i+)MonthCombobox.addItem(new Integer(i)。/Switch th

12、e monthMonthCombobox.setForeground(Color.blue) 。MonthCombobox.setFont(new Font("TimesRoman",Font.BOLD,12)。North.add(Blank=new JLabel(" ")。North.add(Query=new JButton("Query")。Query.setForeground(Color.blue) 。Query.addActionListener(this) 。JPanel North2=new JPanel(new Fl

13、owLayout() 。LeftNorth.add(North2) 。North2.add(PriorMonth=new JButton(new ImageIcon("./images/prior.gif")。PriorMonth.addActionListener(this)。PriorMonth.setActionCommand("prior")。priormonth=month 。prioryear=year 。SwitchMonth(month) 。North2.add(ShowDate=newJLabel(SwitchMonth+"&

14、quot;+","+""+String.valueOf(year),SwingConstants.CENTER)。ShowDate.setForeground(Color.blue) 。ShowDate.setFont(new Font("TimesRoman",Font.BOLD,14)。North2.add(NextMonth=new JButton(new ImageIcon("./images/next.gif")。NextMonth.addActionListener(this)。NextMonth.se

15、tActionCommand("next")。/LeftPane_CenterLeftCenter.setLayout(new GridLayout(7,7)。/print titlefor(int i=0 。 i<7 。 i+)TopBarTitlei=new JLabel() 。TopBarTitlei.setText(weeki)。TopBarTitlei.setForeground(Color.darkGray)。TopBarTitlei.setHorizontalAlignment(0)。TopBarTitlei.setBackground(Color.MA

16、GENTA )。TopBarTitlei.setBorder(BorderFactory.createRaisedBevelBorder()。LeftCenter.add(TopBarTitlei)。/print screen and add listener6/18for(int i=0 。 i<42 。 i+)ShowDaysi=new JTextField() 。ShowDaysi.addMouseListener(this) 。ShowDaysi.setEditable(false) 。LeftCenter.add(ShowDaysi) 。/print the body of m

17、onthPrintMonth(year,month,day) 。/the layout about right of jpaneRightPane = new JPanel(new BorderLayout() 。JPanel RightCenter = new JPanel() 。JPanel RightNorth = new JPanel() 。JPanel RightSouth = new JPanel(new FlowLayout() 。RightPane.add(RightNorth,BorderLayout.NORTH)。RightPane.add(RightCenter,Bord

18、erLayout.CENTER)。RightPane.add(RightSouth,BorderLayout.SOUTH)。RightNorth.add(NorthMonthDayYear=new JLabel(">>"+year+","+SwitchMonth+","+day+"<<")。key=year+"_"+SwitchMonth+"_"+day。NorthMonthDayYear.setForeground(Color.blue) 。Nort

19、hMonthDayYear.setFont(new Font("TimesRoman",Font.BOLD,17)。RightCenter.add(CenterText=new JTextArea("please write today's things.")。CenterText.setLineWrap(true) 。CenterText.setSelectedTextColor(Color.blue) 。/CenterText.addActionListener(this) 。RightSouth.add(SouthSave=new JBut

20、ton("Save") 。SouthSave.setBackground(Color.cyan) 。SouthSave.addActionListener(this) 。SouthSave.setActionCommand("Save") 。RightSouth.add(SouthDelete=new JButton("Delete")。SouthDelete.setBackground(Color.cyan) 。SouthDelete.addActionListener(this) 。SouthDelete.setActionCom

21、mand("Delete") 。this.year = year 。this.month = month 。this.day = day 。/add container to put LeftPane and RightPaneContainer con=getContentPane() 。JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane) 。 /gai bian con.add(split,BorderLayout.CENTER) 。con.validate() 。

22、/add CenterPane to notepad/CenterPane initializesetFont(new Font("Times New Roman",Font.PLAIN,12)。7/18JScrollPane scrollpane = new JScrollPane(CenterText) 。scrollpane.setPreferredSize(new Dimension(220,250) 。RightCenter.add(scrollpane) 。/init randomaccessfile/switch the month in englishpub

23、lic void SwitchMonth(int month)switch(month)case 1:SwitchMonth="Jan" 。 break。case 2:SwitchMonth="Feb" 。 break。case 3:SwitchMonth="Mar"。 break。case 4:SwitchMonth="Apr"。 break。case 5:SwitchMonth="May"。 break。case 6:SwitchMonth="Jun" 。 break。c

24、ase 7:SwitchMonth="Jul" 。 break。case 8:SwitchMonth="Aug"。break。case 9:SwitchMonth="Sep" 。 break。case 10:SwitchMonth="Qct" 。 break。case 11:SwitchMonth="Nov"。 break。case 12:SwitchMonth="Dec" 。 break。/print the body of the monthpublic void Pri

25、ntMonth(int year,int month,int day)/Get start day of the week for the first date in the monthint startday = GetStartDay(year,month) 。/Get number of days in the monthint dayinmonth = GetNumOfDaysInMonth(year,month)。/Print header/PrintTitleAndScreen() 。8/18/Print bodyPrintMonthBody(startday,dayinmonth

26、,day)。/PrintMonth(int year,int month,int day)'s burdenpublic void PrintMonth(int year,int month)/Get start day of the week for the first date in the monthint startday = GetStartDay(year,month) 。/Get number of days in the monthint dayinmonth = GetNumOfDaysInMonth(year,month)。/Print header/Print b

27、odyPrintMonthBody(startday,dayinmonth) 。/PrintMonthBody(int startday,int dayinmonth,int day)'s burden public void PrintMonthBody(int startday,int dayinmonth)for(int i=startday,n=1 。 i<startday+dayinmonth 。 i+)ShowDaysi.setText(""+n) 。ShowDaysi.setHorizontalAlignment(0)。/let centerif

28、(n=day)ShowDaysi.setForeground(Color.green) 。ShowDaysi.setFont(new Font("TimesRoman",Font.BOLD,20)。ShowDaysi.setBackground(Color.DARK_GRAY)。elseShowDaysi.setFont(new Font("TimesRoman",Font.BOLD,12)。ShowDaysi.setForeground(Color.white) 。ShowDaysi.setBackground(Color.DARK_GRAY)。n+

29、。for(int i=0 。 i<startday 。 i+)ShowDaysi.setText("") 。ShowDaysi.setBackground(Color.DARK_GRAY)。for(int i=startday+dayinmonth。i<42 。 i+)ShowDaysi.setText("") 。ShowDaysi.setBackground(Color.DARK_GRAY)。9/18/judge leapyear is or notpublic boolean IsLeapYear(int year)if(year%400

30、=0)|(year%4=0&&year%100!=0)return true 。elsereturn false。/judge the start day of a monthpublic int GetStartDay(int year,int month)/get total number of day since1/1/0000int startday0001=-32768 。long totalnumofdays=GetTotalNumOfDays(year,month)。/return the start dayreturn (int)(totalnumofdays+

31、startday0001)%7)。/judge the days of a yearpublic long GetTotalNumOfDays(int year,int month)long total=0 。/get the total days from -32767 to yearfor(int i=-32767 。 i<year。 i+)if(IsLeapYear(i)total=total+366 。elsetotal=total+365 。/Add days from jan to the month prior to the calendar monthfor(int i=

32、1 。 i<month 。i+)total=total+GetNumOfDaysInMonth(year,i)。return total 。/judge the days of a monthpublic int GetNumOfDaysInMonth(int year,int month)if(month=1 | month=3 | month=5 | month=7 | month=8 | month=10 |month=12)return 31。if(month=4 | month=6 | month=9 | month=11)return 30。if(month=2)10/18i

33、f(IsLeapYear(year)return 29。elsereturn 28。return 0。public void WriteRecord()String content 。content=CenterText.getText() 。int n=content.length() 。char contentarr=new charn 。tryint i=0 。for(i=0 。 i<n 。 i+)contentarri=content.charAt(i) 。File Diary = new File("Diary")。Diary.mkdir() 。File m

34、yfile=new File("Diary"+key+".txt")。FileWriter Record=new FileWriter(myfile)。for(i=0 。 i<contentarr.length 。 i+)Record.write(contentarri) 。Record.close()。JOptionPane.showMessageDialog(this,"Save success!") 。catch(IOException ex)public void ReadRecord()tryString conten

35、t="" 。File myfile=new File("Diary"+key+".txt")。FileReader Record=new FileReader(myfile) 。if(myfile.exists()11/18long b=myfile.length() 。/char contentarr=new charb 。intn=JOptionPane.showConfirmDialog(this,"Todayhaslogs,areyouread?","Confirm",JOptionPa

36、ne.YES_NO_CANCEL_OPTION)。if(n=JOptionPane.YES_OPTION)while(b=Record.read()!=-1)content=content+(char)b 。CenterText.setText(content) 。Record.close()。catch(IOException ex)CenterText.setText("Today has not logs.") 。public void DeleteFile()String filepath="Diary"+key+".txt"

37、。File myfile=new File(filepath)。intn=JOptionPane.showConfirmDialog(this,"Areyousuredeletethefile?","Confirm",JOptionPane.YES_NO_CANCEL_OPTION)。if(n=JOptionPane.YES_OPTION)if(myfile.exists()Runtime rt = Runtime.getRuntime() 。tryrt.exec("cmd /c del "+filepath) 。catch (IOE

38、xception e)e.printStackTrace() 。JOptionPane.showMessageDialog(this,"Delete successed!") 。CenterText.setText("Today has not logs.") 。else12/18JOptionPane.showMessageDialog(this,"The file doesn't exist,delete failured!")。public void AboutActionListenerWay()tryprioryea

39、r=Integer.parseInt(YearText.getText() 。priormonth=MonthCombobox.getSelectedIndex()+1。String StrYearText=YearText.getText() 。changeyearmessage=Integer.parseInt(StrYearText)。changemonthmessage=MonthCombobox.getSelectedIndex()+1 。monthafterquery=changemonthmessage。yearafterquery=changeyearmessage。Switc

40、hMonth(changemonthmessage) 。ShowDate.setText(SwitchMonth+" "+","+" "+String.valueOf(changeyearmessage)。PrintMonth(changeyearmessage,changemonthmessage)。ischange=true。catch(Exception ee)JOptionPane.showMessageDialog(this,"The input format doesn't match",&qu

41、ot;Error",JOptionPane.ERROR_MESSAGE) 。/do actonlistener thingspublic void actionPerformed(ActionEvent eAction)String ActionCommand=eAction.getActionCommand()。/Handle button eventsif(eAction.getSource() instanceof JButton)/Handle the queryif("Query".equals(ActionCommand)tryAboutActionL

42、istenerWay() 。catch(Exception ee)JOptionPane.showMessageDialog(this,"The input format doesn't match","Error",JOptionPane.ERROR_MESSAGE) 。13/18/Handle prior monthif("prior".equals(ActionCommand)if(priormonth>1)priormonth=priormonth-1 。elsepriormonth=12 。prioryear=prioryear-1 。PrintMonth(prioryear,priormonth,day)。SwitchMonth(priormonth) 。ShowDate.se

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1