java万历设计教程 .docx

上传人:C****o 文档编号:13051663 上传时间:2022-04-27 格式:DOCX 页数:24 大小:102.38KB
返回 下载 相关 举报
java万历设计教程 .docx_第1页
第1页 / 共24页
java万历设计教程 .docx_第2页
第2页 / 共24页
点击查看更多>>
资源描述

《java万历设计教程 .docx》由会员分享,可在线阅读,更多相关《java万历设计教程 .docx(24页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。

1、精品名师归纳总结封面可编辑资料 - - - 欢迎下载精品名师归纳总结作者: PanHongliang仅供个人学习Java面对对象课程设计设计题目 :万年历可编辑资料 - - - 欢迎下载精品名师归纳总结系别:运算机与信息科学系专业:运算机科学与技术 学号:2021107208姓名:黄展权 指导老师:张延 旺时间:201年 11 月目 录摘要1关键词1Abstract 1Key words1引言1Introduction 2系统功能结构图21系统模块设计31.1 需求设计31.2开发和运行环境31.3功能设计32 万年历详细设计思路42.1程序设计思路42.2程序运行主界面52.3流程图53 各

2、模块功能实现及代码说明63.1初始化组件63.2初始化数据73.3程序清单83.3.1外观界面83.3.2日期星期选择查询界面可编辑资料 - - - 欢迎下载精品名师归纳总结113.3.3显示星期和日期界面 133.3.4鼠标进入所选日期时显示详细信息的界面 143.3.5显示操作系统当前时间的界面164小结175 参考文献18基于 Myeclipse的万年历运算机科学与技术专业黄展权指导老师 张延旺摘要 :万年历是日常生活中不行或缺的小工具,用万年历我们可以精确的查到当前, 以后或是过去的日期,极大的便利了我们的生活。在万年历上添加了显示本的时间以后会更加精确的显示时间。无论是对于我们同学仍

3、是上班族或是自由职业者需要经常查看和查找万年历来规划自己将要做得一些事情,或是回忆在过去的时间里已经做过的事情,使之更加有利于提升我们的学习或是工作进度。Based on the Myeclipse calendarComputer science and technology professional Huang Zhanquan tutor ZhangYanwangAbstract: Calendar is indispensable in daily life with the calendar gadget, we can accurately find the current, fu

4、ture or past the date, great convenience to our life.On the calendar to add displays the local time will be more accurately show the time.No matter for our students or office workers or freedom occupation needs often view and find million years has traditionally been planning their will to do someth

5、ing, or is the memories in the past time have done, making it more conducive to improve our studyor work in degree.关键词 : JavaKeywords Java引言万年历运行程序得出的界面分为五块,第一块有外观,音乐,说明等功能,可以通过选择三种外观转变万年历的外观,仍可以通过音乐下拉列表播放万年历自带的音乐,假如用户不会使用该万年历,仍可以通过点击说明“按钮”帮忙用户使此万年历,假如用户想可编辑资料 - - - 欢迎下载精品名师归纳总结退出万年历,可以通过点击退出按钮退出。其次

6、块有日期和星期的查询,用户查询完日期之后可以通过今日按钮回到当前日期。第三块为星期和日期面板,用户可以很快查询到对应的日期和星期。第四块为显示当前日期和时间,用户可以更便利明白当前的所在的时 间。第五块为显示作者信息和开发此万年历的时间。IntroductionCalendar program the interface is divided into five pieces, the first piece of music,that have the appearance, function, can be obtained by selecting three kinds of appe

7、arance change calendar appearance, but also through music playback calendardrop-down list with music, if the user does not use the calendar, also can click on thebutton to help users the calendar, if the user wants to withdraw from the calendar,can click the exit button to exit 。 second with a date

8、and week of inquiries, user queries can be finished after the date of this button to return to the current date 。third for the week and date, the user can quickly query to the corresponding date andweek 。 fourth block to display the current date and time, the user can more easily understand the curr

9、ent local time 。 fifth pieces for display author information and development of the calendar time.系统功能结构图:主要描述系统要实现的各个模块的功能。可编辑资料 - - - 欢迎下载精品名师归纳总结CSM播暂循停为为为放停环止默认用户古典的系风外统格观的外观万年历外观音乐查询星期今日查询年月日对应的星期返回当前星期1 系统模块设计1.1 需求分析本程序的要求为:1. 使用图形用户界面2. 能够实现日期与星期的查询1.2 开发和运行环境 开发工具: Myeclipse 运行环境: windows 7

10、1.3 功能设计本程序要构建的万年历程序,其功能有以下几个方面:(1) 通过 JFrame,实现图形界面。(2) 通过外观三个按钮转变日历的外观。(3) 通过点击“说明”按钮,显示日历使用信息。(4) 能以月历形式显示日期与星期。可编辑资料 - - - 欢迎下载精品名师归纳总结(5) 供应年份、月份的下拉形式菜单来选择年份和月份,可以通过今日按钮返回当前日期。(6) 通过点击“查询星期”来查询日期对应的星期。(7) 通过点击“音乐”播放万年历自带的音乐功能。(8) 点击“退出”,可以提示用户是否要退出系统。(9) 显示系统当前时间和日期。(10) 显示作者信息。(11) 鼠标进入当前日期的方块

11、时,可以显示当前的日期,星期,星座, 润平,年农历的大小,农历的天数,农历的干支,如下图所示:2 万年历详细设计思路2.1 程序设计思路(1) 总天数的算法:第一用if语句判确定义年到输入年之间每一年是否为闰年,是闰年,该年的总天数为366,否就,为 365。然后判定输入的年是否为定义年,如是,令总天数 S=1,否就,用累加法运算出定义年到输入年之间的总天数,再把输入年的一月到要输出的月份之间的天数累加起来,如该月是闰年中的月份并且该月仍大于二月,再使总天数加 1,否就,不加,既算出从定义年一月一日到输出年的该月一日的总天数。(2) 输出月份第一天为星期几的算法:使总天数除以7 取余加 2 得

12、几既为星期几,如是7,就为星期日。(3) 算出输出月份第一天为星期几的算法:算出输出月份第一天为星期几后,把该日期以前的位置用空格补上,并总该日起一次输出天数直到月底,该月中的天数加上该月一日为星期几的数字再除以7 得 0 换行,即可完整的输出该月的日历。(4) 假如年份小于 1900 年就程序不予判定。2.2 程序运行主界面2.3 流程图3 各模块功能实现及代码说明可编辑资料 - - - 欢迎下载精品名师归纳总结3.1 初始化组件import java.applet.*。impor t java.awt.*。 import java.awt.event.*。import javax.swin

13、g.*。import javax.swing.border.*。import java.util.*。import java.text.ParseException。import java.text.SimpleDateFormat。import java.util.Calendar。import java.util.Date import java.awt.Colorimport java.awt.Font。import java.text.SimpleDateFormat。import java.util.Date。import javax.swing.JLabel。import java

14、.awt.Font。import java.awt.event.ActionEvent。import java.awt.event.ActionListener。import javax.swing.JButton 。import javax.swing.JDialog 。import javax.swing.JLabel 。3.2 初始化数据publicclass Test extends JFrame implements ActionListener private JLabel datas = new JLabel67。/定义显示一个月的日期private JLabel label =

15、 null。private JPanel panel_Header, panel_Surface, panel_Week, panel_Calendar,panel_Time, panel_Declaration。private JLabel Time = new JLabel。private Calendar calendar = null。private JComboBox year_box = null。private JComboBox month_box = null。private JComboBox date_box = null。private JRadioButton cro

16、ss = null, system = null, motif = null。可编辑资料 - - - 欢迎下载精品名师归纳总结private ButtonGroup feel_group = null。private JMenuBar jmb = null。private JMenu jm = null。private JMenuItem Play,Suspend, Loop,Stop = null。privateint today。private JButton nowday, quit, Query, show_help = null。private AudioClip sound。pub

17、licstaticvoid mainString args SwingConsole. run new Test, 650, 630。public Test /增加日历的各种面板setTitle黄展权的万年历 -实现日期与星期查询 。setIconImagethis.getToolkit.createImagetitle.gif。setResizablefalse。calendar = Calendar.getInstance 。today = calendar.getCalendar.DAY_OF_MON 。TH panel_Surface = initializtion_Surface。p

18、anel_Header = initializtion_Header。 panel_Week = initializtion_Week。 panel_Calendar = initializtion_Calendar。panel_Time = initializtion_Time。panel_Declaration = initializtion_Declaration。setLayoutnull。setBounds185, 125, 0, 0。panel_Calendar.setBounds0, 0, 650, 45。addpanel_Surface。panel_Surface.setBou

19、nds0, 0, 650, 40。addpanel_Header。 panel_Header.setBounds0, 35, 650, 40。addpanel_Week 。panel_Week.setBounds0, 75, 650, 35。addpanel_Time。 panel_Time.setBounds0, 523, 650, 40。addpanel_Declaration。panel_Declaration.setBounds0, 563, 650, 45。addpanel_Calendar。 panel_Calendar.setBounds0, 110, 650, 415。init

20、ializtion_Datacalendar。3.3 程序清单3.3.1 外观界面可编辑资料 - - - 欢迎下载精品名师归纳总结private JPanel initializtion_Surface /添加外观,音乐等面板JPanel panel = new JPanel。panel.setBordernew EtchedBorder1, Color.LIGHT_GRA, YColor.GRAY 。panel.setLayoutnull。panel.setSize650, 40。cross = new JRadioButtonc, false。cross.addActionListener

21、new LookAndFeel_Listener。system = new JRadioButtons, false。system.addActionListenernew LookAndFeel_Listener。motif = new JRadioButtonm, false。motif.addActionListenernew LookAndFeel_Listener。feel_group = new ButtonGroup。feel_group.addcross。feel_group.addsystem。feel_group.addmotif。JLabel look_feel = ne

22、w JLabelpanel.addlook_feel。外观:, JLabel.RIGHT 。look_feel.setBounds100, 10, 38, 25。panel.addcross。cross.setBounds150, 10, 38, 25。panel.addsystem。system.setBounds210, 10, 32, 25。panel.addmotif。motif.setBounds270, 10, 38, 25。jmb = new JMenuBar。jm = new JMenu音乐 。Play = new JMenuItem播放 。Suspend = new JMen

23、uItem暂停 。Loop = new JMenuItem 循环 。Stop = new JMenuItem 停止 。jmb.addjm 。jm.addPlay。jm.addSuspend。jm.addLoop。jm.addStop。Play.addActionListenernew Music_play。Suspend.addActionListenernew Music_suspend。Loop.addActionListenernew Music_loop。Stop.addActionListenernew Music_stop。panel.addjmb。jmb.setBounds350

24、, 7, 50, 25。new ButtonGroup。show_help = new JButton说明 。可编辑资料 - - - 欢迎下载精品名师归纳总结show_help.addActionListenernew Statement。panel.addshow_help。show_help.setBounds450, 7, 65, 25。show_help.setBordernew EmptyBorder0, 0, 0, 0。quit = new JButton退出 。quit.addActionListenernew Quit_Listenner。panel.addquit。quit.

25、setBounds560, 7, 70, 25。/ 读取音乐文件 /.URL file1 = getClass.getResource123.wav。sound = java.applet.Applet.newAudioClip file1。/ return panel。class Music_play implements ActionListener /开头播放音乐publicvoid actionPerformedActionEvent e Play.setEnabledtrue。sound.play。class Music_suspend implements ActionListen

26、er /暂停播放音乐publicvoid actionPerformedActionEvent e Suspend.setEnabledtrue。sound.stop。class Music_loop implements ActionListener /循环播放音乐publicvoid actionPerformedActionEvent e Loop.setEnabledtrue。sound.loop。class Music_stop implements ActionListener /停止播放音乐publicvoid actionPerformedActionEvent e Stop.

27、setEnabledtrue。sound.stop。可编辑资料 - - - 欢迎下载精品名师归纳总结图 1 外观界面3.3.2 日期星期选择查询界面private JPanel initializtion_Header /增加查询日历,星期的面板JPanel panel = new JPanel。year_box = new JComboBox。month_box = new JComboBox。date_box = new JComboBox。panel.setBordernew EtchedBorder5, Color.GRAY, Color.GRAY 。JLabel year_l = n

28、ew JLabel请选择年份 : , JLabel.RIGHT 。JLabel month_l = new JLabelJLabel date_1 = new JLabel月: , JLabel.日: , JLabel.RIGHT 。RIGHT 。panel.setLayoutnull。for int i = 1900panel.setSize650, 45。 i 2050。 i+year_box.addItem + i。for int j = 1。 j = 12。 j+month_box.addItem + j。for int k = 1。 k = 31。 k+date_box.addIte

29、m + k。year_box.setSelectedIndexcalendar.getCalendar.YEAR - 1900。 month_box.setSelectedIndexcalendar.getCalendar.MONTH 。 date_box.setSelectedIndexcalendar.getCalendar.DATE - 1。 nowday = new JButton今日 。nowday.addActionListenernew nowday_Listener。Query = new JButton查询星期 。Query.addActionListenernew Quer

30、y_Listener。panel.addyear_l。year_l.setBounds35, 10, 95, 25。panel.addyear_box。year_box.setBounds135, 10, 65, 25。panel.addmonth_l。month_l.setBounds195, 10, 45, 25。panel.addmonth_box。month_box.setBounds240, 10, 45, 25。panel.adddate_1。 date_1.setBounds280, 10, 45, 25。panel.adddate_box。date_box.setBounds3

31、25, 10, 45, 25。panel.addnowday。 nowday.setBounds390, 10, 80, 25。nowday.setBordernew EmptyBorder0, 0, 0, 0。panel.addQuery。Query.setBounds500, 10, 90, 25。可编辑资料 - - - 欢迎下载精品名师归纳总结Query.setBordernew EmptyBorder0, 0, 0, 0。year_box.addActionListenerthis。month_box.addActionListenerthis。date_box.addActionLi

32、stenerthis。return panel。class nowday_Listener implements ActionListener /点击今日按钮回到当前日期private Date now_data = new Date。 /定义年月日SuppressWarningsdeprecationprivateint now_year = now_data.getYear。/猎取当前的年SuppressWarningsdeprecationprivateint now_month = now_data.getMonth。/猎取当前的月SuppressWarningsdeprecation

33、privateint now_day = now_data.getDate - 1。/猎取当前的日publicvoid actionPerformedActionEvent e year_box.setSelectedIndexnow_year。month_box.setSelectedIndexnow_month date_box.setSelectedIndexnow_day。class Query_Listener implements ActionListener /显示查询日期的面板JDialog dialog = null。publicvoid actionPerformedAct

34、ionEvent e /初始化查询日期数据String S。GregorianCalendar gc = new GregorianCalendar。String input1 = JOptionPane.showInputDialog 请输入年份可编辑资料 - - - 欢迎下载精品名师归纳总结 。 。 。String input2 = JOptionPane.showInputDialog 请输入月份String input3 = JOptionPane.showInputDialog 请输入日期可编辑资料 - - - 欢迎下载精品名师归纳总结int year = Integer.parse

35、Intinput1。int month = Integer.parseInt input2。int date = Integer.parseIntinput3。finalchar kor_week = 日, 一, 二, 三, 四, 五, 六 。gc.setyear, month - 1, date。char week = kor_weekgc.getCalendar.DAY_OF_WEE- K1。S = 您查询的日期是:星期 + week。JOptionPane.showMessageDialognull, S。 /显示查询后日期面板可编辑资料 - - - 欢迎下载精品名师归纳总结图 2 日期

36、星期选择查询界面3.3.3 显示星期和日期界面private JPanel initializtion_Week /增加显示星期的面板JPanel panel = new JPanel。panel.setLayoutnew GridLayout1, 7。String columnNames = 星期日 , 星期一 , 星期二 , 星期三 , 星期四 , 星期五 , 星期六 。JLabel label = null。for int i = 0。 i 7。 i+ label = new JLabelcolumnNamesi, JLabel.CENTER。 / 将日可编辑资料 - - - 欢迎下载精

37、品名师归纳总结期显示在方框的正中间if i = 0 if i = 6 的颜色label.setForegroundColor.RED 。 /显示周日的颜色label.setForegroundColor.GREEN。/显示周六的颜色label.setBordernew LineBorderColor.GRAY 。 /显示边框panel.addlabel。可编辑资料 - - - 欢迎下载精品名师归纳总结return panel。private JPanel initializtion_Calendar /显示日期的面板JPanel panel = new JPanel。panel.setLayo

38、utnew GridLayout6, 7。for int i = 0。 i 6。 i+ for int j = 0。 j 7。 j+ label = new JLabel, JLabel.CENTER。datasij = label。label.setBordernew LineBorderColor.GRAY 。 /显可编辑资料 - - - 欢迎下载精品名师归纳总结示边框的颜色if j = 0 的颜色为红色if j = 6六的颜色为绿色List_MouseListener。return panel。label.setForegroundColor.RED 。 /显示周日label.setForegroundColor.GREEN。 /显示周datasij.addMouseListenernew panel.addlabel。可编辑资料 - - - 欢迎下载精品名师归纳总结图 3 星期和日期显示界面3.3.4 鼠标进入所选日期时显示详细信息的界面publicvoid mouseEnteredMouseEvent e /鼠标进入到组件上时调用。labe = JLabel e.getSource。String lab = labe.getText。可编辑资料 - - - 欢迎下载精品名师归纳总

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知得利文库网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号-8 |  经营许可证:黑B2-20190332号 |   黑公网安备:91230400333293403D

© 2020-2023 www.deliwenku.com 得利文库. All Rights Reserved 黑龙江转换宝科技有限公司 

黑龙江省互联网违法和不良信息举报
举报电话:0468-3380021 邮箱:hgswwxb@163.com