(完整版)java万年历课程
- 格式:pdf
- 大小:169.04 KB
- 文档页数:11
import java.util.Scanner;//蔡勒(Zeller)公式(只适合于1582年10月15日之后的情形):w=y+[y/4]+[c/4]-2c+[26(m+1)/10]+d-1//公式中的符号含义如下: c:世纪(年的高两位数); y:年(年的低两位数);//m:月(m大于等于3,小于等于14,即在蔡勒公式中,某年的1、2月要看作上一年的13、14月来计算,//比如2005年1月1日要看作2004年的13月1日来计算); d:日; []代表取整,即只要整数部分。
//w:星期;w对7取模得:0-星期日,1-星期一,2-星期二,3-星期三,4-星期四, 5-星期五,6-星期六//以2005年2月14日为例:c=20,y=4,m=14,d=14//w = 4 + [4/4] + [20/4] - 2*20 + [26*(14+1)/10] + 14 - 1 = 4 + 1 + 5 - 40 + 39 + 14 - 1 = 22//(除以7余1) 所以2005年2月14日是星期一。
public class PerpetualCalendarII {public static void main(String[] args) {// declare variable month,yearint month, monthDays = 0, year;int firstDayOfMonth, a, b, w;int count = 0;// declare flagboolean flag;Scanner sc = new Scanner(System.in);System.out.println("请输入年份:");year = sc.nextInt();System.out.println("请输入月份:");month = sc.nextInt();// judge year is leap year or notif ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { flag = true;} else {flag = false;}// get days of the monthswitch (month) {case 4:case 6:case 9:case 11:monthDays = 30;break;case 1:case 3:case 5:case 7:case 8:case 10:case 12:monthDays = 31;break;case 2:if (flag == true) {monthDays = 29;} else {monthDays = 28;}}// get the true yearif (month == 1) {month = 13;year -= 1;}if (month == 2) {month = 14;year -= 1;}// judge the firstDayOfMontha = year / 100;b = year % 100;// get the value of ww = b + (b / 4) + (a / 4) - 2 * a + 26 * (month + 1) / 10;if (w % 7 == 0) {firstDayOfMonth = 1;} else {firstDayOfMonth = w % 7;}System.out.println("星期日\t星期一\t星期二\t星期三\t星期四\t星期五\t星期六");// output \tfor (int i = 0; i < firstDayOfMonth; i++) {System.out.print("\t");count++;}//loop daysfor (int i = 1; i <= monthDays; i++) {System.out.print(i + "\t");count++;if (count % 7 == 0) {System.out.println();}}}}。
import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.DefaultTableModel;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.Locale;import java.util.TimeZone;public class wannianli extends JFrame implements ActionListener, MouseListener {private Calendar cld = Calendar.getInstance();//获取一个Calendar类的实例对象private String[] astr = { "星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日" };private DefaultTableModel dtm = new DefaultTableModel(null, astr);private JTable table = new JTable(dtm);private JScrollPane sp = new JScrollPane(table);private JButton bLastYear = new JButton("上一年");private JButton bNextYear = new JButton("下一年");private JButton bLastMonth = new JButton("上月");private JButton bNextMonth = new JButton("下月");private JPanel p1 = new JPanel(); // 设立八个中间容器,装入布局控制日期的按钮模块private JPanel p2 = new JPanel(new GridLayout(3,2));//网格布局private JPanel p3 = new JPanel(new BorderLayout());//边界布局private JPanel p4 = new JPanel(new GridLayout(2,1));private JPanel p5 = new JPanel(new BorderLayout());private JPanel p6 = new JPanel(new GridLayout(2,2));private JPanel p7 = new JPanel(new GridLayout(2,1));private JPanel p8 = new JPanel(new BorderLayout());private JComboBox timeBox = newJComboBox(TimeZone.getAvailableIDs());//对所有支持时区进行迭代,获取所有的id;private JTextField jtfYear = new JTextField(5);// jtfYeaar年份显示输入框private JTextField jtfMonth = new JTextField(2);// jtfMouth月份显示输入框private JTextField timeField=new JTextField();//各城市时间显示框private static JTextArea jta = new JTextArea(10,5);//农历显示区private JScrollPane jsp = new JScrollPane(jta);private JLabel l = new JLabel("花江小精灵:亲!你可以直接输入年月查询.");private JLabel lt = new JLabel();private JLabel ld = new JLabel();private JLabel lu = new JLabel("农历和节气");private JLabel null1=new JLabel();private int lastTime;//private String localTime = null;private String s = null;private SimpleDateFormat dateFormat=new SimpleDateFormat("yyyy年MM月dd 日 hh时mm分ss秒");public wannianli() {super("花江日历过去仅留追忆,未来刚生憧憬,唯有坚守本心,把握今天 ZYT 詹永堂 ");// 框架命名this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 窗口关闭函数this.getContentPane().setLayout(new BorderLayout(9, 10));jta.setLineWrap(true);// 长度大于分配长度时候则换行jta.setFont(new Font("黑体", Font.BOLD, 16));table.setBackground(Color.white);table.setGridColor(Color.pink);// 星期之间的网格线是灰色的table.setBackground(Color.white);table.setColumnSelectionAllowed(true);// 将table中的列设置为可选择的table.setSelectionBackground(Color.pink);// 当选定某一天时背景颜色为黑色table.setSelectionForeground(Color.GREEN);table.setBackground(new Color(184,207, 229));// 日期显示表格为浅蓝色table.setFont(new Font("黑体", Font.BOLD, 24));// 日期数字字体格式table.setRowHeight(26);// 表格的高度table.addMouseListener(this); // 鼠标监听器、lu.setFont(new Font("黑体", Font.BOLD, 22));//农历标签格氏jtfYear.addActionListener(this);// 可输入年份的文本框// 为各个按钮添加监听函数bLastYear.addActionListener(this);bNextYear.addActionListener(this);bLastMonth.addActionListener(this);bNextMonth.addActionListener(this);timeBox.addItemListener(new TimeSelectedChangedListener());// 将按钮添加到Jpane上p1.add(bLastYear);p1.add(jtfYear);// 年份输入文本框p1.add(bNextYear);p1.add(bLastMonth);p1.add(jtfMonth);p1.add(bNextMonth);p3.add(jsp, BorderLayout.SOUTH);p3.add(lu,BorderLayout.CENTER);p3.add(ld, BorderLayout.NORTH);p4.add(lt);p4.add(l);p5.add(p4, BorderLayout.SOUTH);p5.add(sp, BorderLayout.CENTER);p5.add(p1, BorderLayout.NORTH);p6.add(timeBox);p6.add(null1);p6.add(timeField);p8.add(p2,BorderLayout.CENTER);p8.add(p7,BorderLayout.SOUTH);this.getContentPane().add(p3, BorderLayout.EAST);this.getContentPane().add(p5, BorderLayout.CENTER);this.getContentPane().add(p6,BorderLayout.SOUTH);this.getContentPane().add(p8,BorderLayout.WEST);String[] strDate = DateFormat.getDateInstance().format(new Date()) .split("-");// 获取日期cld.set(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1]) - 1,0);showCalendar(Integer.parseInt(strDate[0]),Integer.parseInt(strDate[1]), cld);jtfMonth.setEditable(false);// 设置月份文本框为不可编辑jtfYear.setText(strDate[0]);jtfMonth.setText(strDate[1]);this.showTextArea(strDate[2]);ld.setFont(new Font("新宋体", Font.BOLD, 24));new Timer(lt).start();new TimeThread().start();this.setBounds(200, 200, 700, 350);this.setResizable(false);this.setVisible(true);}public void showCalendar(int localYear, int localMonth, Calendar cld) {int Days = getDaysOfMonth(localYear, localMonth) +cld.get(Calendar.DAY_OF_WEEK) -2;Object [] ai = new Object[7];lastTime = 0;for (int i = cld.get(Calendar.DAY_OF_WEEK)-1; i <= Days; i++) {ai[i%7] =String.valueOf(i-(cld.get(Calendar.DAY_OF_WEEK)-2));if (i%7 == 6){dtm.addRow(ai);ai = new Object[7];lastTime++;}}dtm.addRow(ai);}public int getDaysOfMonth(int Year, int Month) {//计算各月的天数if(Month==1||Month==3||Month==5||Month==7||Month==8||Month==10||Mont h==12){return 31;}if(Month==4||Month==6||Month==9||Month==11){return 30;}if(Year%4==0&&Year%100!=0||Year%400==0)//闰年{return 29;}else {return 28;}}public void actionPerformed(ActionEvent e)//从界面上获取年月数据{if(e.getSource() == jtfYear || e.getSource() == bLastYear || e.getSource() == bNextYear ||e.getSource() == bLastMonth || e.getSource() == bNextMonth){int m, y;try//控制输入的年份正确,异常控制{if (jtfYear.getText().length() != 4){throw new NumberFormatException();}y = Integer.parseInt(jtfYear.getText());m = Integer.parseInt(jtfMonth.getText());}catch (NumberFormatException ex){JOptionPane.showMessageDialog(this, "请输入4位0-9的数字!", "年份有误", JOptionPane.ERROR_MESSAGE);return;}ld.setText("没有选择日期");for (int i = 0; i < lastTime+1; i++){ dtm.removeRow(0);}if(e.getSource() ==bLastYear){ jtfYear.setText(String.valueOf(--y)); }if(e.getSource() ==bNextYear){jtfYear.setText(String.valueOf(++y)); }if(e.getSource() == bLastMonth){if(m == 1){jtfYear.setText(String.valueOf(--y));m = 12;jtfMonth.setText(String.valueOf(m));}else{jtfMonth.setText(String.valueOf(--m));}}if(e.getSource() == bNextMonth){if(m == 12){jtfYear.setText(String.valueOf(++y));m = 1;jtfMonth.setText(String.valueOf(m));}else{jtfMonth.setText(String.valueOf(++m));}}cld.set(y, m-1, 0);showCalendar(y, m, cld);}}public void mouseClicked(MouseEvent e){jta.setText(null);int r = table.getSelectedRow();int c = table.getSelectedColumn();if (table.getValueAt(r,c) == null){ld.setText("没有选择日期");}else{this.showTextArea(table.getValueAt(r,c));}}private void showTextArea(Object selected){ld.setText(jtfYear.getText()+"年"+jtfMonth.getText()+"月"+selected+"日");}public static void main(String[] args){JFrame.setDefaultLookAndFeelDecorated(true);JDialog.setDefaultLookAndFeelDecorated(true);new wannianli();jta.setText(today());}private void updateTimeText(String timeZoneId) {if(timeZoneId != null){TimeZone timeZone = TimeZone.getTimeZone(timeZoneId);dateFormat.setTimeZone(timeZone);Calendar calendar = Calendar.getInstance();calendar.setTimeZone(timeZone);timeField.setText(dateFormat.format(calendar.getTime()));}else{timeField.setText(null);}}private class TimeSelectedChangedListener implements ItemListener { public void itemStateChanged(ItemEvent e) {if (e.getStateChange()==ItemEvent.SELECTED) {if (e.getItem() instanceof String) {s = e.getItem().toString();}}}}private class TimeThread extends Thread{public void run(){while(true){updateTimeText(s);try{Thread.sleep(100);}catch(InterruptedException e){e.printStackTrace();}}}}class Timer extends Thread //显示系统时间{private JLabel lt;private SimpleDateFormat fy = new SimpleDateFormat(" Gyyyy.MM.dd HH:mm:ss ");public Timer(JLabel lt){this.lt=lt;}public void run(){while(true){try{lt.setText(fy.format(new Date()));this.sleep(500);}catch(InterruptedException ex){ex.printStackTrace();}}}}final private static long[] lunarInfo= new long[] { 0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554,0x056a0, 0x09ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0,0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0x06d40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566,0x0d4a0, 0x0ea50, 0x06e95, 0x05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550,0x056a0, 0x1a5b4, 0x025d0, 0x092d0, 0x0d2b2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355, 0x04da0, 0x0a5d0,0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0x0f263,0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0,0x195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0x06d40, 0x0af46, 0x0ab60, 0x09570, 0x04af5,0x04970, 0x064b0, 0x074a3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, 0x0d954, 0x0d4a0,0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0x0baa4, 0x0ad50, 0x055d9,0x04ba0, 0x0a5b0, 0x15176, 0x052b0, 0x0a930, 0x07954, 0x06aa0, 0x0ad50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0,0x0d260, 0x0ea65, 0x0d530, 0x05aa0, 0x076a3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520,0x0dd45, 0x0b5a0, 0x056d0, 0x055b2, 0x049b0, 0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0x06d20, 0x0ada0 };final private static int[] year20 = new int[] { 1, 4, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };final private static int[] year19 = new int[] { 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };final private static int[] year2000 = new int[] { 0, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1 };public final static String[] nStr1 = new String[] { "", "正", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一","十二" };private final static String[] Gan = new String[] { "甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸" };private final static String[] Zhi = new String[] { "子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥" };private final static String[] Animals = new String[] { "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊", "猴", "鸡", "狗", "猪" };// 传回农历 y年的总天数final private static int lYearDays(int y) {int i, sum = 348;for (i = 0x8000; i > 0x8; i >>= 1) {if ((lunarInfo[y - 1900] & i) != 0)sum += 1;}return (sum + leapDays(y));}// 传回农历 y年闰月的天数final private static int leapDays(int y) {if (leapMonth(y) != 0) {if ((lunarInfo[y - 1900] & 0x10000) != 0)return 30;elsereturn 29;} elsereturn 0;}// 传回农历 y年闰哪个月 1-12 , 没闰传回 0final private static int leapMonth(int y) {return (int) (lunarInfo[y - 1900] & 0xf);}//传回农历 y年m月的总天数final private static int monthDays(int y, int m) {if ((lunarInfo[y - 1900] & (0x10000 >> m)) == 0)return 29;elsereturn 30;}// 传回农历 y年的生肖final public static String AnimalsYear(int y) {return Animals[(y - 4) % 12];}//传入月日的offset 传回干支,0=甲子final private static String cyclicalm(int num) {return (Gan[num % 10] + Zhi[num % 12]);}// 传入 offset 传回干支, 0=甲子final public static String cyclical(int y) {int num = y - 1900 + 36;return (cyclicalm(num));}// 传出农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6final private long[] Lunar(int y, int m) {long[] nongDate = new long[7];int i = 0, temp = 0, leap = 0;Date baseDate = new GregorianCalendar(1900 + 1900, 1,31).getTime();Date objDate = new GregorianCalendar(y + 1900, m, 1).getTime();long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;if (y < 2000)offset += year19[m - 1];if (y > 2000)offset += year20[m - 1];if (y == 2000)offset += year2000[m - 1];nongDate[5] = offset + 40;nongDate[4] = 14;for (i = 1900; i < 2050 && offset > 0; i++) {temp = lYearDays(i);offset -= temp;nongDate[4] += 12;}if (offset < 0) {offset += temp;i--;nongDate[4] -= 12;}nongDate[0] = i;nongDate[3] = i - 1864;leap = leapMonth(i); // 闰哪个月nongDate[6] = 0;for (i = 1; i < 13 && offset > 0; i++) {// 闰月if (leap > 0 && i == (leap + 1) && nongDate[6] == 0) { --i;nongDate[6] = 1;temp = leapDays((int) nongDate[0]);} else {temp = monthDays((int) nongDate[0], i);}// 解除闰月if (nongDate[6] == 1 && i == (leap + 1))nongDate[6] = 0;offset -= temp;if (nongDate[6] == 0)nongDate[4]++;}if (offset == 0 && leap > 0 && i == leap + 1) {if (nongDate[6] == 1) {nongDate[6] = 0;} else {nongDate[6] = 1;--i;--nongDate[4];}}if (offset < 0) {offset += temp;--i;--nongDate[4];}nongDate[1] = i;nongDate[2] = offset + 1;return nongDate;}// 传出y年m月d日对应的农历.year0 .month1 .day2 .yearCyl3 .monCyl4 .dayCyl5 .isLeap6final public static long[] calElement(int y, int m, int d) {long[] nongDate = new long[7];int i = 0, temp = 0, leap = 0;Date baseDate = new GregorianCalendar(0 + 1900, 0, 31).getTime();Date objDate = new GregorianCalendar(y, m - 1, d).getTime();long offset = (objDate.getTime() - baseDate.getTime()) / 86400000L;nongDate[5] = offset + 40;nongDate[4] = 14;for (i = 1900; i < 2050 && offset > 0; i++) {temp = lYearDays(i);offset -= temp;nongDate[4] += 12;}if (offset < 0) {offset += temp;i--;nongDate[4] -= 12;}nongDate[0] = i;nongDate[3] = i - 1864;leap = leapMonth(i); // 闰哪个月nongDate[6] = 0;for (i = 1; i < 13 && offset > 0; i++) {// 闰月if (leap > 0 && i == (leap + 1) && nongDate[6] == 0) { --i;nongDate[6] = 1;temp = leapDays((int) nongDate[0]);} else {temp = monthDays((int) nongDate[0], i);}// 解除闰月if (nongDate[6] == 1 && i == (leap + 1))nongDate[6] = 0;offset -= temp;if (nongDate[6] == 0)nongDate[4]++;}if (offset == 0 && leap > 0 && i == leap + 1) { if (nongDate[6] == 1) {nongDate[6] = 0;} else {nongDate[6] = 1;--i;--nongDate[4];}}if (offset < 0) {offset += temp;--i;--nongDate[4];}nongDate[1] = i;nongDate[2] = offset + 1;return nongDate;}public final static String getChinaDate(int day) { String a = "";if (day == 10)return"初十";if (day == 20)return"二十";if (day == 30)return"三十";int two = (int) ((day) / 10);if (two == 0)a = "初";if (two == 1)a = "十";if (two == 2)a = "廿";if (two == 3)a = "三";int one = (int) (day % 10);switch (one) {case 1:a += "一";break;case 2:a += "二";break;case 3:a += "三";break;case 4:a += "四";break;case 5:a += "五";break;case 6:a += "六";break;case 7:a += "七";break;case 8:a += "八";break;case 9:a += "九";break;}return a;}public static String today() {Calendar today = Calendar.getInstance(Locale.SIMPLIFIED_CHINESE);int year = today.get(Calendar.YEAR);int month = today.get(Calendar.MONTH) + 1;int date = today.get(Calendar.DATE);long[] l = calElement(year, month, date);StringBuffer sToday = new StringBuffer();try {sToday.append(sdf.format(today.getTime()));sToday.append(" \n");sToday.append(" \n");sToday.append(" \n");sToday.append(" 农历");sToday.append(cyclical(year));sToday.append('(');sToday.append(AnimalsYear(year));sToday.append(")年");sToday.append(" \n");sToday.append(" ");sToday.append(nStr1[(int) l[1]]);sToday.append("月");sToday.append(getChinaDate((int) (l[2])));return sToday.toString();} finally {sToday = null;}}private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy 年M月d日 EEEEE");public void mouseEntered(MouseEvent e) {}public void mouseExited(MouseEvent e) {}public void mousePressed(MouseEvent e) {}public void mouseReleased(MouseEvent e) { }}。
Java中的⽇期和时间类以及Calendar类⽤法详解Java⽇期和时间类简介Java 的⽇期和时间类位于 java.util 包中。
利⽤⽇期时间类提供的⽅法,可以获取当前的⽇期和时间,创建⽇期和时间参数,计算和⽐较时间。
Date 类Date 类是 Java 中的⽇期时间类,其构造⽅法⽐较多,下⾯是常⽤的两个:Date():使⽤当前的⽇期和时间初始化⼀个对象。
Date(long millisec):从1970年01⽉01⽇00时(格林威治时间)开始以毫秒计算时间,计算 millisec 毫秒。
如果运⾏ Java 程序的本地时区是北京时区(与格林威治时间相差 8 ⼩时),Date dt1=new Date(1000);,那么对象 dt1 就是1970年01⽉01⽇08时00分01秒。
请看⼀个显⽰⽇期时间的例⼦:import java.util.Date;public class Demo{public static void main(String args[]){Date da=new Date(); //创建时间对象System.out.println(da); //显⽰时间和⽇期long msec=da.getTime();System.out.println("从1970年1⽉1⽇0时到现在共有:" + msec + "毫秒");}}运⾏结果:Mon Feb 05 22:50:05 CST 2007从1970年1⽉1⽇0时到现在共有:1170687005390 毫秒⼀些⽐较常⽤的 Date 类⽅法:Date 对象表⽰时间的默认顺序是星期、⽉、⽇、⼩时、分、秒、年。
若需要修改时间显⽰的格式可以使⽤“SimpleDateFormat(String pattern)”⽅法。
例如,⽤不同的格式输出时间:import java.util.Date;import java.text.SimpleDateFormat;public class Demo{public static void main(String args[]){Date da=new Date();System.out.println(da);SimpleDateFormat ma1=new SimpleDateFormat("yyyy 年 MM ⽉ dd ⽇ E 北京时间");System.out.println(ma1.format(da));SimpleDateFormat ma2=new SimpleDateFormat("北京时间:yyyy 年 MM ⽉ dd ⽇ HH 时 mm 分 ss 秒");System.out.println(ma2.format(-1000));}}运⾏结果:Sun Jan 04 17:31:36 CST 20152015 年 01 ⽉ 04 ⽇星期⽇北京时间北京时间:1970 年 01 ⽉ 01 ⽇ 07 时 59 分 59 秒Calendar 类抽象类 Calendar 提供了⼀组⽅法,允许把以毫秒为单位的时间转换成⼀些有⽤的时间组成部分。
万年历程序设计说明书一、引言万年历是一种常见的日历工具,用于显示日期和计算日期间的差异。
本说明书旨在介绍万年历程序的设计原理和功能,帮助用户更好地理解和使用该程序。
二、程序设计原理1. 数据结构万年历程序主要基于日期的计算和显示,因此需要设计合适的数据结构来存储日期信息。
常用的数据结构包括日期对象、月份对象和年份对象。
2. 界面设计万年历程序需要提供用户友好的界面,以便用户能够方便地输入和查看日期信息。
界面设计应简洁明了,同时考虑不同屏幕尺寸和分辨率的适配。
3. 算法设计万年历程序的核心功能是日期的计算和显示。
算法设计应能够准确计算日期间的差异,包括年份、月份和天数的计算。
同时,还需要考虑闰年和月份天数不同的情况。
三、功能介绍1. 日期查询用户可以通过输入日期来查询该日期的详细信息,包括星期几、所在月份和年份等。
程序应能够准确显示查询结果并提供相关操作选项。
2. 日期计算用户可以输入两个日期,程序将计算并显示这两个日期之间的差异,包括相差的年份、月份和天数。
程序应能够处理闰年和月份天数不同的情况。
3. 节假日提醒万年历程序可以提供节假日的提醒功能,用户可以设置节假日的提醒日期和提醒方式。
程序应能够准确提醒用户,并提供相应的操作选项。
4. 日期转换用户可以输入不同的日期格式,程序将自动转换为标准的日期格式进行计算和显示。
程序应支持常见的日期格式,并提供错误处理机制。
四、程序设计实现1. 开发环境万年历程序可以使用各种编程语言和开发工具进行实现。
常见的开发环境包括Java、Python、C++等。
选择合适的开发环境可以提高开发效率和程序性能。
2. 数据库设计万年历程序可以使用数据库存储节假日和相关数据,以便程序查询和显示。
数据库设计应考虑数据的结构和索引,提高数据的查询效率和程序的响应速度。
3. 界面设计万年历程序的界面设计应简洁明了,用户可以方便地输入和查看日期信息。
界面设计可以使用图形界面或命令行界面,根据实际需求选择合适的设计方式。
*******************实践教学*******************兰州理工大学计算机与通信学院2012年秋季学期Java 课程设计题目:万年历的设计专业班级:姓名:学号:指导教师:成绩:目录摘要 (2)序言 (3)正文 (4)一、系统分析与设计 (4)二、详细设计 (5)2.1 类Calendars (5)2.2 类Time (5)2.3 类CalTabel (5)三、系统测试 (6)四、软件使用说明书 (9)设计总结 (10)参考文献 (11)致谢 (12)附录1(源代码) (13)摘要根据万年历的需要,设计一个万年历的程序,实现在此万年历表中有关日期和时间的基本操作:显示当时系统的日期和时间;显示当日的年和月;通过查询显示指定年、月的日历;设置北京时间,以显示北京和格林威治的时间并以设定的时间开始计时。
设置时间和查询日历通过设计的窗体执行和显示。
关键词:万年历;图形界面;java技术序言1996年Java第一次发布就引起了人们的极大兴趣。
关注Java的人士不仅限于计算机出版界,还有诸如《纽约时报》、《华盛顿邮报》、《商业周刊》这样的主流媒体。
Java时第一种也是唯一一种在National Public Radio上占用了十分钟时间进行介绍的程序设计语言,并且还得到了$100 000 000的风险投资基金。
这些基金全部用来支持这种特别的计算机语言开发的产品。
Java语言在Internet舞台上以及亮相便名声大噪,其原因在于它将有望成为连接用户与信息的万能胶,而不论这些信息来源于Web服务器、数据库、信息提供商,还是任何其他渠道,Java固有的可靠性与安全性不仅令Java程序员放心,也令使用Java程序的用户放心。
而此次将用Java设计一个万年历表,我们更加了解Java面向对象的程序设计语言。
正文一、系统分析与设计1、系统的要求(1)定义一个时间类Time,能提供时、分、秒组成的时间,并提供时间增加的方法(按秒);(2)定义一个日期类Date,记录年、月、日,并提供日期增加的方法(按天);(3)由类Time和日期类Date,派生出DateTime类,除具有年、月、日、时、分、秒外,还增加国名和与格林威治时间的差;(4)输入年、月、日、时、分、秒,在屏幕上模拟显示一电子计时器,不断输出下一秒的时间和日期,以及格林威治的日期和时间。
摘要:本实训报告旨在通过对万年历的设计与应用,加深对时间管理、编程技术以及用户界面设计的理解。
通过实训,我们不仅学会了万年历的基本原理,还掌握了编程实现和用户体验优化的方法。
以下是对实训过程的详细记录和分析。
一、实训目的1. 理解万年历的基本原理和设计思路。
2. 掌握编程语言(如Python、Java等)在万年历开发中的应用。
3. 提升用户界面设计能力,优化用户体验。
4. 培养团队合作与沟通能力。
二、实训环境1. 操作系统:Windows 102. 开发工具:Python3.8、PyCharm3. 用户界面设计工具:Qt Designer4. 数据库:SQLite三、实训原理万年历是一种用于记录和显示日历的工具,它按照公历或农历的日期排列,方便用户查看和查询。
万年历的设计原理主要包括以下几个方面:1. 闰年判断:通过判断年份是否为4的倍数来确定是否为闰年,同时还需考虑能被100整除但不能被400整除的年份不是闰年。
2. 月份天数:根据月份和闰年/非闰年的判断来确定每月的天数。
3. 星期计算:根据年、月、日计算出星期几。
4. 农历转换:根据农历的算法将公历日期转换为农历日期。
四、实训过程1. 确定项目需求:根据实训要求,设计一个功能齐全、界面友好的万年历软件。
2. 设计软件架构:确定软件的模块划分,包括主界面、日期计算、农历转换等模块。
3. 编写代码实现:使用Python语言实现万年历的各个功能模块。
4. 用户界面设计:使用Qt Designer设计软件的用户界面,包括日期选择、查询结果展示等。
5. 数据库设计:使用SQLite数据库存储万年历的数据,包括日期、农历信息等。
6. 调试与优化:对软件进行调试,修复可能出现的问题,并优化用户体验。
五、实训结果1. 成功实现万年历的基本功能,包括公历和农历的日期转换、查询等。
2. 软件界面简洁美观,用户操作方便。
3. 数据库设计合理,保证了数据的完整性和安全性。
万年历课程设计一、课程目标知识目标:1. 学生能够理解万年历的基本概念,掌握年、月、日的关系及其换算方法。
2. 学生能够运用所学的知识,制作并解释简单万年历,了解闰年和平年的判断规则。
3. 学生能够解释生活中的时间单位,如时、分、秒,并掌握它们之间的换算。
技能目标:1. 学生通过实际操作,学会制作和应用简单万年历,提升解决问题的能力和动手实践能力。
2. 学生能够运用万年历进行日期查询和推算,增强逻辑思维和计算能力。
3. 学生通过合作交流,提高表达和沟通能力,培养团队协作精神。
情感态度价值观目标:1. 学生培养对时间管理和计划安排的意识,养成珍惜时间、合理规划的好习惯。
2. 学生在学习过程中,体验探索和发现的乐趣,激发对自然科学和数学的兴趣。
3. 学生通过了解不同文化背景下的时间观念,增强跨文化理解和尊重多元文化的态度。
课程性质:本课程以实践性、探究性和趣味性为主要特点,结合数学、自然科学和社会文化知识,帮助学生建立时间观念,提高综合运用知识的能力。
学生特点:考虑到学生的年级特点,课程设计将注重直观演示和实际操作,以激发学生的兴趣和好奇心,同时结合学生的认知水平,逐步引导他们掌握万年历的制作和应用。
教学要求:教师在教学过程中,应关注学生的个体差异,提供个性化的指导和支持。
课程设计应注重培养学生的动手能力、逻辑思维能力和团队协作能力,确保学生能够达到预定的学习目标。
二、教学内容1. 年、月、日的概念及其关系- 介绍年、月、日的定义和相互关系。
- 年份的种类:闰年和平年的区别及判断方法。
2. 万年历的制作原理- 探索如何将日历与天文数据相结合,介绍格里高利历的基本原理。
- 学习如何通过计算确定每个月的天数,以及如何安排闰年的2月。
3. 日期的换算与查询- 学习日期的换算方法,如年与日、日与星期等。
- 实践操作:使用万年历进行日期查询和推算。
4. 实际应用与时间管理- 讨论如何利用万年历进行时间规划和管理。
软件学院课程设计报告书课程名称面向对象课程设计设计题目专业班级学号姓名指导教师年 1 月int selYear1=Integer.parseInt(calLis.Year.getSelectedItem());int selYear = selYear1- 1900;Date d1 = new Date(selYear,selMonth,1);int day = d1.getDay();calLis.setVal(d1,day,selMonth,selYear);}}class myAction implements ActionListener{CalenderCreator calAc;int newyear;public myAction(CalenderCreator ca{calAc=ca;}//为“关闭”按钮添加监听事件,当“关闭”按钮被点击时就执行这里的部分public void actionPerformed(ActionEvent e){String s=calAc.textfield.getText();// newyear=Integer.parseInt(s);System.out.println("Year upto::::::::"+s);calAc.setYear(s);TextField tf = (TextField)e.getSource();tf.removeActionListener(this);}}4.3用图片辅助认识程序的具体操作和执行图4-1:月份和年份的效果图图4-2:星期的效果图图4-3:日期的效果图图4-4:日历整体效果图4.4附注完整程序设计import java.awt.*;import java.awt.event.*;import java.util.*;public class CalenderCreator extends Frame{Button days[]=new Button[49];Choice Month=new Choice();Choice Year=new Choice();Label lmonth=new Label("MONTH");Label lyear=new Label("Year");Label ltext=new Label("YEAR UPTO");Panel p1,p2;GregorianCalendar gc=new GregorianCalendar();int totdays;TextField textfield=new TextField(2);public CalenderCreator(){setTitle("日历");setSize(400,400);。