java程序设计报告2万年历.doc_第1页
java程序设计报告2万年历.doc_第2页
java程序设计报告2万年历.doc_第3页
java程序设计报告2万年历.doc_第4页
java程序设计报告2万年历.doc_第5页
已阅读5页,还剩13页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

程序设计报告JAVA设计报告2:万年历姓 名: 王 颖学 号:61541220314001学习中心:延安富县学习中心专 业:计算机科学与技术层 次: 专升本身份证号系电话万年历程序设计一、设计分析万年历有很多作用,顾名思义它是一种很方便得计时计年工具,随着科技得发展,我们已经可以通过计算机制作出精美的万年历,通过计算机制作得万年历不但外观美观,而且功能强大。通过万年历,我们可以实现很多功能,随意看某年得年份,某年得月份,随意调整某年得某天,并将其显示出来,而且有判断闰年闰月得功能,十分方便。开始初始化读、写日期、时间分离日期时间显示子程序农历自动更新子程序日期、时间修改子程序闰月子程返回定时子程序 二、程序流程框图 主程序流程图 三、具体设计1、变量设计 表2变量表成员变量描述变量类型名称年、月、日intYear、month、day下一年,下一月IntYearafterquery,monthafterquey开始的时间Intstartday选择月,天StringSwitchMonth,key,day改变年改变月前一月,前一年判断是否改变左、又面板年、月左上角信息标签显示月、年标签空格标签右上部时间标签星期标签数组月份下拉列表时间确定按钮保存、删除按钮前、下一月按钮文本区星期字符串数组显示天的文本区输入年的文本区IntIntIntbooleanJPanelJLabelJLabelJLabelJLabelJLabelJLabelJComboBoxJButtonJButtonJButtonJTextAreaStringJTextFieldJTextFieldChangeyearmessagechangemonthmessagepriormonth,prioryearischange,ischange_priornextLeftPane,RightPaneYearLabel,MonthLabelAskShowDateBlankNorthMonthDayYearTopBarTitleMonthComboboxQuerySouthSave,SouthDeletePriorMonth,NextMonthCenterTextweekShowDaysYearText2、程序源代码import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.border.*; import java.util.Calendar; import java.util.*; import java.io.*; import java.io.IOException; public 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=false; private JPanel LeftPane,RightPane; /Left sub private JLabel YearLabel; private JLabel MonthLabel; private JComboBox MonthCombobox; private JTextField ShowDays= new JTextField42; private JTextField YearText;private JLabel Ask; private JLabel ShowDate; private JLabel Blank; private JLabel TopBarTitle=new JLabel7; private JButton ToToday; private JButton Query; private String week=SUN,MON,TUE,WED,THU,FRI,SAT;/right subprivate JLabel NorthMonthDayYear; private 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 jpane LeftPane = new JPanel(); JPanel LeftCenter = new JPanel(); JPanel LeftNorth = new JPanel(); /JPanel LeftSouth = new JPanel(); LeftPane.setLayout(new BorderLayout(); LeftPane.add(LeftNorth,BorderLayout.NORTH); LeftPane.add(LeftCenter,BorderLayout.CENTER); LeftPane.add(ToToday = new JButton(Go to today,new ImageIcon(./images/Handle.gif),BorderLayout.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 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); YearText.addActionListener(this); YearText.setFocusable(true);North.add(Blank=new JLabel( ); North.add(MonthLabel = new JLabel(Month:); North.add(MonthCombobox = new JComboBox(); /add month to monthcombobox for(int i=1;i=12;i+) MonthCombobox.addItem(new Integer(i); /Switch the month MonthCombobox.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 FlowLayout(); 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 = new JLabel(SwitchMonth+ +,+ +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.setActionCommand(next); /LeftPane_Center LeftCenter.setLayout(new GridLayout(7,7); /print title for(int i=0;i7;i+) TopBarTitlei=new JLabel(); TopBarTitlei.setText(weeki); TopBarTitlei.setForeground(Color.darkGray); TopBarTitlei.setHorizontalAlignment(0); TopBarTitlei.setBackground(Color.MAGENTA ); TopBarTitlei.setBorder(BorderFactory.createRaisedBevelBorder();LeftCenter.add(TopBarTitlei); /print screen and add listener for(int i=0;i+year+,+SwitchMonth+,+day+);key=year+_+SwitchMonth+_+day;NorthMonthDayYear.setForeground(Color.blue); NorthMonthDayYear.setFont(new Font(TimesRoman,Font.BOLD,17);RightCenter.add(CenterText=new JTextArea(please write todays things.);CenterText.setLineWrap(true);CenterText.setSelectedTextColor(Color.blue);/CenterText.addActionListener(this);RightSouth.add(SouthSave=new JButton( 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.setActionCommand(Delete);this.year = year;this.month = month;this.day = day;/add container to put LeftPane and RightPane Container con=getContentPane(); JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,RightPane,LeftPane);/gai bian con.add(split,BorderLayout.CENTER); con.validate();/add CenterPane to notepad/CenterPane initializesetFont(new Font(Times New Roman,Font.PLAIN,12); JScrollPane scrollpane = new JScrollPane(CenterText);scrollpane.setPreferredSize(new Dimension(220,250); RightCenter.add(scrollpane); /init randomaccessfile /switch the month in english public 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; case 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 month public void PrintMonth(int year,int month,int day) /Get start day of the week for the first date in the month int startday = GetStartDay(year,month); /Get number of days in the month int dayinmonth = GetNumOfDaysInMonth(year,month); /Print header /PrintTitleAndScreen(); /Print body PrintMonthBody(startday,dayinmonth,day); /PrintMonth(int year,int month,int day)s burden public void PrintMonth(int year,int month) /Get start day of the week for the first date in the month int startday = GetStartDay(year,month); /Get number of days in the month int dayinmonth = GetNumOfDaysInMonth(year,month); /Print header /Print body PrintMonthBody(startday,dayinmonth); /PrintMonthBody(int startday,int dayinmonth,int day)s burden public void PrintMonthBody(int startday,int dayinmonth) for(int i=startday,n=1;istartday+dayinmonth;i+) ShowDaysi.setText(+n); ShowDaysi.setHorizontalAlignment(0);/let center if(n=day) ShowDaysi.setForeground(Color.green); ShowDaysi.setFont(new Font(TimesRoman,Font.BOLD,20); ShowDaysi.setBackground(Color.DARK_GRAY); else ShowDaysi.setFont(new Font(TimesRoman,Font.BOLD,12); ShowDaysi.setForeground(Color.white); ShowDaysi.setBackground(Color.DARK_GRAY); n+; for(int i=0;istartday;i+) ShowDaysi.setText();ShowDaysi.setBackground(Color.DARK_GRAY);for(int i=startday+dayinmonth;i42;i+)ShowDaysi.setText();ShowDaysi.setBackground(Color.DARK_GRAY);/judge leapyear is or notpublic boolean IsLeapYear(int year)if(year%400=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+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;iyear;i+)if(IsLeapYear(i)total=total+366;elsetotal=total+365;/Add days from jan to the month prior to the calendar monthfor(int i=1;imonth;i+)total=total+GetNumOfDaysInMonth(year,i); return total; /judge the days of a month public 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) if(IsLeapYear(year) return 29; else return 28; return 0; public void WriteRecord() String content; content=CenterText.getText(); int n=content.length(); char contentarr=new charn; try int i=0; for(i=0;in;i+) contentarri=content.charAt(i); File Diary = new File(Diary); Diary.mkdir(); File myfile=new File(Diary+key+.txt); FileWriter Record=new FileWriter(myfile);for(i=0;i1) priormonth=priormonth-1; else priormonth=12; prioryear=prioryear-1; PrintMonth(prioryear,priormonth,day); SwitchMonth(priormonth); ShowDate.setText(SwitchMonth+ , +prioryear); NorthMonthDayYear.setText(+SwitchMonth+,+day+,+prioryear+); key=prioryear+_+SwitchMonth+_+day; ischange_priornext=true; /Handle next month if(next.equals(ActionCommand) if(priormonth+SwitchMonth+,+day+,+prioryear+year+SwitchMonth+,+day+,+SwitchMonth+,+day+,+year+SwitchMonth+,+day+,+prioryear+SwitchMonth+,+day+,+changeyearmessage+SwitchMonth+,+day+,+prioryear+); key=prioryear+_+SwitchMonth+_+day; ReadRecord(); catch(Exception ee) public void mouseClicked(MouseEvent e) public void mouseReleased(MouseEvent e) public void mouseEntered(MouseEvent e) public void mouseExited(MouseEvent e) public void SaveLog(int year,int month,int day) public static void main(String args) throws Exception Calendar calendar=Calendar.getInstance(); int y=calendar.get(Calendar.YEAR); int m=c

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论