Java日历记事本
java日历记事本小游戏当前时间代码

rightPanel=new JPanel();
this.year=year;
this.month=month;
this.day=day;
负责改变年=new Year(this);
private static final long serialVersionUID = -1805873342285018876L;
int a,b,c;
WindowButton Game;
Timer Time;
CalendarPad 开始=null;
fileMenu1.add(item1);
fileMenu1.add(item2);
fileMenu1.add(item3);
bar.add(fileMenu1);
win.setMenuBar(bar);
win.add(la,BorderLayout.CENTER);
item1=new MenuItem("日历记事本");
bar=new MenuBar();
fileMenu1=new Menu("菜单选项");
item2=new MenuItem("小游戏");
item3=new MenuItem("当前时间");
if(e.getSource()==item2)
{Game=new WindowButton("小游戏");
Game.setVisible(true);}
if(e.getSource()==item3)
{ Calendar calendar=Calendar.getInstance();
java控制台输出万年历

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();}}}}。
Java万年历源代码,可显示公历、农历、系统时间、国际时间

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课程设计记事本设计报告

java课程设计记事本设计报告一、教学目标本课程旨在通过Java编程语言实现一个记事本应用程序,让学生掌握Java编程的基本概念和方法,培养学生的编程能力和解决问题的能力。
1.理解Java编程语言的基本语法和结构。
2.掌握Java编程中的数据类型、变量、运算符、控制语句等基本概念。
3.学习Java中的类和对象的概念,理解封装、继承和多态的原理。
4.熟悉Java中的常用类库和方法。
5.能够运用Java编程语言编写简单的程序。
6.能够使用Java编程语言实现一个记事本应用程序,包括文本的增删改查等功能。
7.能够分析并解决编程过程中遇到的问题。
情感态度价值观目标:1.培养学生的团队合作意识和沟通能力,通过小组合作完成项目。
2.培养学生的创新思维和解决问题的能力,鼓励学生进行自主学习和探索。
3.培养学生的学习兴趣和自信心,让学生感受到编程的乐趣和成就感。
二、教学内容本课程的教学内容主要包括Java编程语言的基本概念和方法,以及记事本应用程序的设计和实现。
1.Java编程语言的基本概念和方法:–数据类型、变量、运算符、控制语句等基本概念。
–类和对象的概念,封装、继承和多态的原理。
–常用类库和方法的使用。
2.记事本应用程序的设计和实现:–用户界面设计:创建文本框、按钮等控件,实现用户输入和显示功能。
–文件操作:实现文件的打开、保存、关闭等功能,使用文件读写技术。
–文本处理:实现文本的增删改查等功能,使用数据结构和算法进行文本管理。
三、教学方法本课程将采用多种教学方法,包括讲授法、讨论法、案例分析法和实验法等,以激发学生的学习兴趣和主动性。
1.讲授法:教师通过讲解Java编程语言的基本概念和方法,以及记事本应用程序的设计和实现,引导学生掌握相关知识。
2.讨论法:学生分组进行讨论,分享自己的理解和思路,互相学习和交流。
3.案例分析法:分析实际案例,让学生了解记事本应用程序的实际应用场景和设计思路。
4.实验法:学生通过编写代码和进行实验,实现记事本应用程序的功能,培养学生的实际编程能力和解决问题的能力。
java日历小程序

java日历小程序简介:Java日历小程序是一个基于Java语言开发的工具,用于显示和管理日期和时间。
它提供了一种简单而直观的方式来查看、创建和编辑日历事件,并提供了一些额外的功能,如提醒、重复事件和时间段的计算等。
本文将详细介绍Java日历小程序的功能、使用方法和设计原理。
功能:1. 显示日历:Java日历小程序可以显示当前月份的日历,并以日、周或月的形式展示。
用户可以通过界面上的上下翻页按钮切换月份,方便查看不同日期的日历。
2. 创建和编辑事件:用户可以通过Java日历小程序创建新的日历事件,并为每个事件指定标题、日期、时间和地点等详细信息。
程序还提供了事件编辑功能,允许用户修改已有事件的信息。
3. 提醒功能:Java日历小程序可以设置事件的提醒功能,提醒用户在指定的时间前提醒。
用户可以选择在事件开始前几分钟、几小时或几天提醒,并可以自定义提醒方式,如弹窗、声音或邮件通知等。
4. 重复事件:用户可以为事件设置重复功能,使事件在指定的日期间隔内重复发生。
可以选择每天、每周、每月或每年重复,并可以设置重复的结束日期。
5. 时间段计算:Java日历小程序可以计算两个日期之间的时间段,如计算两个事件之间的天数、小时数或分钟数等。
用户可以选择计算方式,并获取精确的时间段结果。
使用方法:1. 下载和安装:用户可以从官方网站上下载Java日历小程序的安装包,然后按照安装向导进行安装。
安装完成后,用户可以在桌面或开始菜单中找到程序的快捷方式。
2. 打开程序:双击程序的快捷方式,Java日历小程序将启动并显示当前月份的日历。
用户可以通过界面上的按钮和菜单来使用各种功能。
3. 创建事件:用户可以点击界面上的“添加事件”按钮,弹出一个对话框,输入事件的详细信息,如标题、日期、时间和地点等。
点击“确定”按钮后,事件将被创建并显示在日历上。
4. 编辑事件:用户可以在日历上点击已有的事件,弹出一个对话框,允许用户修改事件的信息。
简单日历程序

import java.util.Scanner;public class CalendarDemo{public static void main(String[] args) {int sum = 0;Scanner in = new Scanner(System.in);System.out.print("请输入年份:");int year = in.nextInt();Scanner sc = new Scanner(System.in);System.out.print("请输入月份:");int month = sc.nextInt();for (int i = 1900; i <= year; i++) {if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) {sum += 366;} else {sum += 365;}}for (int i1 = 1; i1 <= month; i1++) {if (i1 == 2) {if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {sum += 29;}/** for(int i=1;i<=29;i++){ if(sum%7==6){* System.out.print(i+"\n"); } else{* System.out.print(i+"\t"); } sum++; break; }*/else{sum += 28;}/** for(int i=1;i<=28;i++){** if(sum%7==6){ System.out.print(i+"\n"); } else{* System.out.print(i+"\t"); } sum++; break;* }*/} else if (i1 == 1 || i1 == 3 || i1 == 5 || i1 == 7 || i1 == 8|| i1 == 10 || i1 == 12) {sum += 31;/** for(int i=1;i<=31;i++){ if(sum%7==6){* System.out.print(i+"\n"); } else{ System.out.print(i+"\t"); }* sum++; break; }*/} else {sum += 30;/** for(int i=1;i<=30;i++){ if(sum%7==6){* System.out.print(i+"\n"); } else{ System.out.print(i+"\t"); }* sum++; break; }*/}}sum += 1;System.out.println("从1900年1月1日到"+year+"年"+month+"月1日总共是"+sum+"天");System.out.println("从1900年1月1日到"+year+"年"+month+"月1日是星期"+(sum%7));int weekday;weekday = sum % 7;System.out.println("日\t一\t二\t三\t四\t五\t六");for (int i = 1; i <= weekday; i++) {System.out.print("\t");}if(month==2){if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0){for (int i = 1; i <= 29; i++) {if (sum % 7 == 6) {System.out.print(i + "\n");} else {System.out.print(i + "\t");}sum++;continue;}}else{for (int i = 1; i <= 28; i++) {if (sum % 7 == 6) {System.out.print(i + "\n");} else{System.out.print(i + "\t");}sum++;continue;}}}else if(month==4||month==6||month==9||month==11){for (int i = 1; i <= 30; i++) {if (sum % 7 == 6) {System.out.print(i + "\n");} else {System.out.print(i + "\t");}sum++;continue;}}else{for (int i = 1; i <= 31; i++) {if (sum % 7 == 6) {System.out.print(i + "\n");} else {System.out.print(i + "\t");}sum++;continue;}}}}/* public static void main(String[] args){ Calendar cal= Calendar.getInstance(); * int a=cal.get(Calendar.YEAR); if(a%4==0&&a%100!=0||a%400==0){* System.out.println(a+"是闰年"); }else System.out.println(a+"不是闰年"); } } */。
java日历课程设计报告

软件学院课程设计报告书课程名称面向对象课程设计设计题目专业班级学号姓名指导教师年 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);。
java万年历源代码(可运行)

private JScrollPane sp = new JScrollPane(table);
private JButton bLastYear = new JButton("上一年");
p3.add(jsp, BorderLayout.CENTER);
p3.add(p2, BorderLayout.SOUTH);
p3.add(ld, BorderLayout.NORTH);
private JTextArea jta = new JTextArea(); //jta--JTextArea
private JScrollPane jsp = new JScrollPane(jta);
private JLabel l = new JLabel("年份文本框中可直接键入要查找的年份,以提高查询效率");
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
//import java.sql.Date;
cld.set(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1])-1, 0);
showCalendar(Integer.parseInt(strDate[0]), Integer.parseInt(strDate[1]), cld);
java获取年月日的方法

Java获取年月日的方法在Java编程中,我们经常需要获取当前的年、月和日。
这些信息在许多应用程序中都是必需的,例如日历应用、日期处理和数据分析等。
本文将介绍几种获取年月日的方法,帮助你在Java中轻松地处理日期。
1. 使用Java.util.Date类Java.util.Date类是Java中处理日期和时间的基本类之一。
要获取当前的年、月和日,可以使用以下代码:import java.util.Date;import java.text.SimpleDateFormat;public class Main {public static void main(String[] args) {Date date = new Date();SimpleDateFormat sdfYear = new SimpleDateFormat("yyyy");SimpleDateFormat sdfMonth = new SimpleDateFormat("MM");SimpleDateFormat sdfDay = new SimpleDateFormat("dd");String year = sdfYear.format(date);String month = sdfMonth.format(date);String day = sdfDay.format(date);System.out.println("Year: " + year);System.out.println("Month: " + month);System.out.println("Day: " + day);}}在上面的代码中,我们使用了SimpleDateFormat类来格式化日期。
通过传入不同的格式化模式,我们可以获取所需的日期部分。
JAVA--简单记事本源代码

JAVA--简单记事本源代码import javax.swing.JFrame;import javax.swing.JTextArea;import java.awt.*;import java.awt.event.*;import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.FileReader;import java.io.FileWriter;import javax.swing.*;import javax.swing.plaf.FileChooserUI;public class notepad extends JFrame implements ActionListener{//定义所需要的组件JTextArea jta=null;JMenuBar jmb=null;JMenu jm=null;JMenuItem jmi1=null;JMenuItem jmi2=null;public static void main(String[]args){new notepad();}public notepad(){//把组件添加到窗体上jta=new JTextArea();jmb=new JMenuBar();this.add(jta);this.setJMenuBar(jmb);//设置窗体属性this.setTitle("简易记事本");this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setSize(400, 300);this.setVisible(true);//把菜单添加进菜单条jm=new JMenu("⽂件");jm.setMnemonic('f');jmb.add(jm);//把⼦菜单加⼊⾄菜单jmi1=new JMenuItem("打开");jmi2=new JMenuItem("保存");jmi1.setActionCommand("open");jmi2.setActionCommand("save");jm.add(jmi1);jm.add(jmi2);//为两个字菜单注册事件监听jmi1.addActionListener(this);jmi2.addActionListener(this);}public void actionPerformed(ActionEvent e){//对点击了打开进⾏处理if(e.getActionCommand().equals("open")){//创建⼀个⽂件选择组件JFileChooser jfc1=new JFileChooser();//设置⽂件选择器的名字jfc1.setDialogTitle("请选择⽂件....");//设置⽂件选择组件的类型(打开类型)jfc1.showOpenDialog(null);//显⽰该组件jfc1.setVisible(true);//获取选择⽂件的绝对路径String s;s=jfc1.getSelectedFile().getAbsolutePath();//将该⽂件显⽰到记事本上BufferedReader br=null;FileReader fr=null;try{//创建⼀个带缓冲的⽂件读取对象fr=new FileReader(s);br=new BufferedReader(fr);String text="";String m=null;//循环读取⽂件while((m=br.readLine())!=null){text+=m+"\r\n";}//将读取的结果打印到记事本上⾯this.jta.setText(text);}catch(Exception e1){e1.printStackTrace();}finally{//关掉打开的⽂件try{br.close();fr.close();}catch(Exception e2){e2.printStackTrace();}}}else if(e.getActionCommand().equals("save")){//创建⼀个⽂件选择组件JFileChooser jfc=new JFileChooser();//设置⽂件选择的名称jfc.setDialogTitle("另存为");//设置⽂件选择组件的类型(保存类型)jfc.showSaveDialog(null);//显⽰该组件jfc.setVisible(true);//获取选择⽂件的绝对路径String filename;filename=jfc.getSelectedFile().getAbsolutePath(); //将记事本内的⽂本保存⾄该路径BufferedWriter bw=null;FileWriter fw=null;try{//创建⽂件输出⽂件fw=new FileWriter(filename);bw=new BufferedWriter(fw);//获取⽂本String outtext="";outtext=this.jta.getText();//输出⽂本fw.write(outtext);}catch(Exception e2){e2.printStackTrace();}finally{//关闭打开的输出⽂件try{bw.close();fw.close();}catch(Exception e3){e3.printStackTrace();}}}}}。
java万年历程序代码

package pack;import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.Calendar;import java.util.Date;public class rili extends JFrame implements ActionListener { JButton b_today, b_query;JLabel lb_Year, lb_Month;JButton b_week[] = new JButton[7];JButton b_day[][] = new JButton[6][7];Container thisContainer;JPanel pUp;JPanel pCenter;JPanel pCenter_week, pCenter_day;JComboBox year, month;public void init() {b_today = new JButton("Today");b_query = new JButton("Query");setTitle("日历");lb_Year = new JLabel("Year");lb_Month = new JLabel("Month");year = new JComboBox();month = new JComboBox();setDate();pUp = new JPanel();pUp.add(lb_Year);pUp.add(year);pUp.add(lb_Month);pUp.add(month);pUp.add(b_today);pUp.add(b_query);b_today.addActionListener(this);b_query.addActionListener(this);pCenter = new JPanel();pCenter_week = new JPanel();b_week[0] = new JButton("星期日");b_week[1] = new JButton("星期一");b_week[2] = new JButton("星期二");b_week[3] = new JButton("星期三");b_week[4] = new JButton("星期四");b_week[5] = new JButton("星期五");b_week[6] = new JButton("星期六");b_week[0].setSize(400, 200);b_week[1].setSize(400, 200);b_week[2].setSize(400, 200);b_week[3].setSize(400, 200);b_week[4].setSize(400, 200);b_week[5].setSize(400, 200);b_week[6].setSize(400, 200);for (int i = 0; i < 7; i++) {b_week[i].setEnabled(false);pCenter_week.add(b_week[i]);}pCenter_day = new JPanel();for (int cols = 0; cols < 6; cols++) {for (int rows = 0; rows < 7; rows++) {b_day[cols][rows] = new JButton("");b_day[cols][rows].setSize(400, 200);this.pCenter_day.add(b_day[cols][rows]);}}pCenter_day.setLayout(new GridLayout(6, 7));setDay(Integer.parseInt(this.year.getSelectedItem().toString()),Integer.parseInt(this.month.getSelectedItem().toString()));// setDay(2011,2);pCenter.setLayout(new BorderLayout());pCenter.add(pCenter_week, "North");pCenter.add(pCenter_day, "Center");thisContainer = this.getContentPane();thisContainer.setLayout(new BorderLayout());thisContainer.add(pUp, "North");thisContainer.add(pCenter, "Center");this.setVisible(true);this.setResizable(false);this.pack();}public void setDate() {int year, month, day, week;Calendar cal = Calendar.getInstance();year = cal.get(Calendar.YEAR);month = cal.get(Calendar.MONTH);day = cal.get(Calendar.DA TE);week = cal.get(Calendar.WEEK_OF_YEAR);int year_temp = year - 4;for (int i = 0; i < 10; i++) {this.year.addItem(year_temp);year_temp += 1;}this.year.setSelectedIndex(4);for (int n = 0; n < 12; n++) {this.month.addItem(n + 1);}this.month.setSelectedIndex(month);}public void setDay(int Year, int Month) {int count;Calendar c = Calendar.getInstance();c.clear();c.set(Year, Month-1, 1);count = c.getActualMaximum(Calendar.DAY_OF_MONTH); // 总天数System.out.print(count);int day = c.get(Calendar.DAY_OF_WEEK) - 1; // 0为星期天,6为星期六System.out.print(day);int i = 1 - day;for (int cols = 0; cols < 6; cols++) {for (int rows = 0; rows < 7; rows++) {String st = String.valueOf(i);b_day[cols][rows].setText(st);b_day[cols][rows].setEnabled(false);if (i > 0 && i <= count)b_day[cols][rows].setVisible(true);elseb_day[cols][rows].setVisible(false);i++;}}}public void actionPerformed(ActionEvent e) {if (e.getSource() == b_query) {this.setDay(Integer.parseInt(this.year.getSelectedItem().toString()), Integer.parseInt(this.month.getSelectedItem().toString()));}if (e.getSource() == b_today) {int year, month;Calendar cal = Calendar.getInstance();year = cal.get(Calendar.YEAR);month = cal.get(Calendar.MONTH)+1;this.setDay(year,month);}}public static void main(String[] args) {rili rl = new rili();rl.init();}}。
Java开发日历记事本

E m i xj cc e. — a : s@cc. t n l l n c
h t :ww d z .e .n t / w.n sn t p/ o
Te h+8 55l 56 96 56 09 4 6— 一 90 3 9 6
C m ue K o  ̄d ea d T c n l y电脑 知识 与技术 o p tr n we g n e h o g o
号 码 排 列算 法 : 方 法包 含 两 个 整 形 参 数 , 该 分别 是 星期 几 和 月 天数 。该 方法 的作 用是 将 日期 一 次 排 列 人 日历 牌 的 网格 中 , 日期
2算 法描述
主 类 的算 法 :a n aP d类 首先 创 建 用 于 布 局 的 面 板 , 面 添 加 日历 牌 , 面 添加 记事 本 。然后 调 用 C ln aPd方 法 , 方 法 C l dra e 左 右 a d ra e 该
有 三 个 分 别 是 y a, n , a e r mo t d y的整 形 参 数 。该 方 法 管 理 日历 记 事 本 的 主 界 面 。在 E历 牌 部 分 使 用 网格 布 局 , h t 行数 和列 数 均 为 7 。其 中第 一 行 显示 星期 标 题 的标 签 . 续 六 行 显 示 日期 的标 签 。 后
g g .Thebai unc on fCae d rh v r w s a a em odfe . ua e s f t so l n a a e b o e nd d t c i i d The i bai unci so N o e a v np , a ,d lt ,ve . scf ton .f t p d ha e i ut sve ee e iw
java桌面课程设计记事本

java桌面课程设计记事本一、教学目标本课程的目标是让学生掌握Java语言实现桌面应用程序的基本技能,通过学习Java语言基础和GUI编程,培养学生的编程能力和解决实际问题的能力。
在知识目标方面,要求学生掌握Java语言基本语法、面向对象编程思想、常用类库和GUI组件的使用。
在技能目标方面,要求学生能够独立设计并实现一个桌面记事本应用程序,掌握Java编程的基本流程。
在情感态度价值观目标方面,培养学生的团队合作意识,提高学生解决问题的能力,使学生认识到计算机编程在实际应用中的重要性。
二、教学内容本课程的教学内容主要包括Java语言基础、面向对象编程、GUI编程和桌面应用程序设计。
具体包括以下几个部分:1.Java语言基础:Java语言的基本语法、数据类型、运算符、控制结构、数组、字符串等。
2.面向对象编程:类与对象、封装、继承、多态、接口、集合等。
3.GUI编程:Swing组件、事件处理、布局管理、菜单栏、工具栏等。
4.桌面应用程序设计:记事本应用程序的需求分析、设计、实现和测试。
三、教学方法为了提高学生的学习兴趣和主动性,本课程将采用多种教学方法相结合的方式。
包括:1.讲授法:讲解Java语言基础、面向对象编程和GUI编程的基本概念和原理。
2.案例分析法:分析典型的桌面应用程序案例,引导学生学会分析问题和解决问题。
3.实验法:让学生动手编写代码,实现桌面记事本应用程序,提高学生的实际操作能力。
4.讨论法:学生进行小组讨论,分享学习心得和经验,培养学生的团队合作意识。
四、教学资源为了支持教学内容和教学方法的实施,丰富学生的学习体验,我们将准备以下教学资源:1.教材:《Java核心技术卷I》、《Java GUI编程》等。
2.参考书:《Java编程思想》、《Effective Java》等。
3.多媒体资料:教学PPT、视频教程、在线代码示例等。
4.实验设备:计算机、网络环境、编程软件(如Eclipse、IntelliJ IDEA等)。
java根据时间截取年月日方法

标题:Java中时间截取年月日的方法摘要:在Java中,我们经常需要对日期进行处理,其中时间截取年月日是一个常见的需求。
本文将通过具体的代码示例,介绍Java中时间截取年月日的方法,帮助读者更好地理解和应用这一技巧。
正文:1. 使用Calendar类进行时间截取在Java中,我们可以使用Calendar类来对日期进行处理,其中包括时间截取年月日的方法。
具体示例代码如下:```javaimport java.util.Calendar;public class TimeTruncateDemo {public static void m本人n(String[] args) {Calendar calendar = Calendar.getInstance();int year = calendar.get(Calendar.YEAR);int month = calendar.get(Calendar.MONTH) + 1;int day = calendar.get(Calendar.DAY_OF_MONTH);System.out.println("年:" + year);System.out.println("月:" + month);System.out.println("日:" + day);}}```在上述示例中,我们通过Calendar类的getInstance方法获取当前时间,然后分别使用get方法获取年、月、日,并打印输出。
2. 使用SimpleDateFormat类进行时间截取除了使用Calendar类,我们还可以使用SimpleDateFormat类来实现时间截取。
示例代码如下:```javaimport java.text.SimpleDateFormat;import java.util.Date;public class TimeTruncateDemo {public static void m本人n(String[] args) {Date date = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");String yearMonthDay = sdf.format(date);System.out.println("年月日:" + yearMonthDay);}}```在上述示例中,我们创建了一个SimpleDateFormat实例,并指定了日期的格式为"yyyy-MM-dd",然后调用format方法对时间进行格式化,得到年月日的字符串。
java编程记事本代码

import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class Notepad extends JFrame {係统组件声明private JMenuBar menuBar = new JMe nuBar(; private JEditorPa ne content = new JEditorPa ne(; private JScrollPa ne scroll = new JScrollPa ne(c ontent; private JFileChooser filechooser = new JFileChooser(; private BorderLayout bord = new BorderLayout(; private JLabel statusBar = new JLabel(; private JPanel pane = new JPanel(; private File file = null; /定义文件菜单private JMenu fileMenu = new JMenu(; private JMenultem newMenultem = new JMenultem(; private JMe nultem ope nMen ultem = new JMe nultem(; private JMe nultem saveMe nultem = new JMe nultem(; private JMe nultem saveAsMe nultem = new JMe nultem(; private JMe nultem pageSetupMe nultem = new JMe nultem(; private JMe nultem prin tMe nultem = new JMe nultem(; private JMe nultem exitMe nultem = new JMenultem(; // 定义风格菜单private JMenu styleMenu = new JMenu(; private Butt on Group styleMe nu Group = new Butt on Group(; private JRadioButt onMen ultem javaStyleMe nultem = new JRadioButt onMen ultem(; private JRadioButt onMen ultem metalStyleMe nultem = new JRadioButt onMen ultem(; private JRadioButt onMen ultem windowsStyleMenultem = new JRadioButtonMenultem(; // 定义帮助菜单private JMe nultem aboutMe nultem = new JMe nultem(; private JMe nultem helpTopicMe nultem =new JMenultem(; private JMenu helpMenu = new JMenu(; 〃构造函数public Notepad({ initComponents(; } private void initComponents({ // 添加子菜单项到文件菜单fileMe nu.setText("\u6587\u4ef6 (F"; n ewMe nultem.setText(” 新建(NCtrl+N"; ope nMen ultem.setText(” 打开(O…Ctrl+O"; saveMe nultem.setText(”保存(S Ctrl+S"; saveAsMenultem.setText(” 另存为(A..."; pageSetupMenultem.setText(” 页面设置(U..."; printMenultem.setText(” 打印(P... Ctrl+P"; exitMe nultem.setText(” 退出";fileMe nu.add( newMe nultem;fileMe nu .add(ope nMen ultem; fileMe nu .add(saveMe nultem; fileMe nu .add(saveAsMe nultem; fileMe nu.addSeparator(; fileMenu.add(pageSetupMenultem;fileMenu.add(printMenultem; fileMe nu.addSeparator(; fileMe nu.add(exitMe nultem; // 添加子菜单项到风格菜单styleMe nu.setText(‘ 风格(S"; javaStyleMe nultem.setText("Java 默认";metalStyleMe nultem.setText("Metal 风格";wi ndowsStyleMe nultem.setText("Wi ndows 风格";styleMe nuGroup.add(javaStyleMe nultem;styleMe nuGroup.add(metalStyleMe nuItem;styleMe nu Group.add(wi ndowsStyleMe nultem; styleMe nu .add(javaStyleMe nultem; styleMe nu.add(metalStyleMe nultem; styleMe nu.add(wi ndowsStyleMe nultem; // 添加子菜单项到帮助菜单helpMenu.setText(‘帮助(H"; helpTopicMenultem.setText(” 帮助主题(H"; aboutMenultem.setText(” 关于记事本(A";helpMe nu .add(helpTopicMe nultem; helpMe nu .addSeparator(;helpMe nu .add(aboutMe nultem; //定义文件菜单下的事件监听n ewMe nultem.addActio nListe ner(new n ewMe nultem_actio nAdapter(this; ope nMen ultem.addActio nListe ner(new ope nMen ultem_actio nAdapter(this; saveMenultem.addActio nListe ner(new saveMe nultem_actio nAdapter(this; saveAsMe nultem.addActio nListe ner(new saveAsMe nultem_actio nAdapter(this; pageSetupMe nultem.addActio nListe ner(new pageSetupMe nultem_actio nAdapter(this; prin tMe nultem.addActi on Liste ner(n ew prin tMe nultem_actio nAdapter(this;exitMenultem.addActionListener(new exitMenultem_actionAdapter(this; // 定义风格菜单下的事件监听javaStyleMenultem.addActionListener(newjavaStyleMenultem_actionAdapter(this; metalStyleMenultem.addActionListener(new metalStyleMe nultem_actio nAdapter(this;wi ndowsStyleMe nultem.addActio nListe ner(newwi ndowsStyleMe nultem_actio nAdapter(this; // 定义帮助菜单下的事件监听helpTopicMe nultem.addActio nListe ner(new helpTopicMe nultem_actio nAdapter(this; aboutMe nultem.addActio nListe ner(new aboutMe nultem_actio nAdapter(this; 〃填加菜单至U菜单栏menuBar.add(fileMenu; menuBar.add(styleMenu; menuBar.add(helpMenu; // 对主窗口的一些设置this.setDefaultCloseOperation(EXIT_ON_CLOSE; this.setTitle(" 纪生的记事本";this.setSize(640,480; setJMenuBar(menuBar; pane.setLayout(bord;pane.add("Center",scroll; setContentPane(pane; } /定义新建菜单项方法public void newMe nultemActio nPeformed(Actio nEve nt evt{ file = nu II;if(!("".equals(co nten t.getText({ Object]] optio ns = {" 是(Y "," 否(N "," 取消"}; int s = JOptio nPan e.showOptio nDialog( null, "\u6587\u4ef6 "+getTitIe(+"\u7684\u6587\u5b57\u5df2\u7ecf\u6539\u53d8\u3002\n\u60f3\u4fdd\u5b58\u6587\u4ef6 \u5417\uff1f", "\u8bb0\u4e8b\u672c", JOptio nPan e.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]; switch(s{ case 0: int returnVal=filechooser.showSaveDialog(this; if(returnVal ==JFileChooser.APPROVE_OPTION { file=filechooser.getSelectedFile(; try{ FileWriterfw=new FileWriter(file; fw.write(co nten t.getText(;setTitle(filechooser.getSelectedFile(.getName(+" - \u8bb0\u4e8b\u672c"; fw.close(; } catch(Excepti on e{ e.pri ntStackTrace(; } break; } case 1: conten t.setText(""; setTitle("无标题-\u8bb0\u4e8b\u672c"; } } } // 定义打开菜单项方法public voidope nMen ultemActio nPeformed(Actio nEve nt evt{ try { file = n ull; int returnVal = filechooser.showOpenDialog(this; if(returnVal ==JFileChooser.APPROVE_OPTION{ file = filechooser.getSelectedFile(; FileReader fr = new FileReader(file; int len = (in tfile .len gth(; char[] buffer = new char[le n]; fr.read(buffer,0,le n; fr.close(; conten t.setText (newString(buffer; } } catch(Exception e{ e.printStackTrace(; } } // 定义退出菜单项方法public void exitMe nultem_actio nPeformed(Actio nEve nte{ if(!("".equals(co nte nt.getText({ Object]] optio ns = {" 是(Y "," 否(N "," 取消"}; int s = JOptionPane.showOptionDialog(null,"文件的文字已经改变。
JSP 实现日历

JSP 实现日历
通过上面JavaBean相关知识的介绍,我们对JavaBean的相关概念已有了初步了解,为了加深知识的巩固,在这里用实现一个日历作指导,介绍一下JavaBean相关知识的应用。
(1)日历Bean实现。
日历Bean类CalcendarBean.java主要实现了年、月、日
在此文件中,使用getIntance方法创建了抽象类Calendar的对象calendar,setTime方法设置calendar对象的时间为当前时间。
使用get方法获得calendar对象的不同字段的值。
(2)日历显示。
日历显示功能是利用JSP的动作元素<jsp:getProperty/>和标记元素<jsp:useBean/>来完成的,实现该显示的功能的文件calendar.jsp的代码如下所
(3)实现日历显示。
将以上文件保存,打开IE浏览器,在地址栏输入http://l ocalhost:8080/stu/calendar.jsp,单击【转到】按钮,就会显示当前日历的相关信息,如图4-14所示。
图4-14 日历显示。
jdate参数

jdate参数一、概述jdate参数是Java中用于处理日期和时间的常用参数。
它提供了多种日期和时间的格式和转换方式,以便在Java应用程序中方便地处理日期和时间数据。
二、常见参数1. DateFormatSymbols:用于指定日期和时间的符号集,包括星期、月份、日期等。
2. SimpleDateFormat:用于根据指定的格式化规则将日期和时间转换为字符串或从字符串解析日期和时间。
3. Epoch(EpochSecond、EpochDay):表示从1970年1月1日0时0分0秒(UTC)到当前时间的秒数或天数。
4. TimeZone:表示时区的信息,用于将日期和时间转换为本地时间。
5. Locale:表示语言环境的信息,用于指定日期和时间的格式和转换规则。
三、常用方法1. getCalendarType():返回用于表示日期的Calendar类型,例如GregorianCalendar等。
2. getTimeZone():返回用于处理日期和时间的时区对象。
3. format(Date date, StringBuffer toAppendTo, FieldPosition pos):将Date对象格式化为字符串,并追加到StringBuffer中。
4. parse(String dateInText, DateFormatSymbols symbols, SimpleDateFormat format, Calendar cal):根据给定的格式化规则将字符串解析为Date对象。
5. getDate(int year, int month, int day):根据年、月、日获取相应的Date对象。
6. getTime(Date date):返回指定Date对象的Time部分。
7. getDateInstance(int style):根据样式返回一个Date对象实例,用于表示特定的日期格式。
日历记事本

课程设计报告课程:面向对象程序设计学号:姓名:班级:计算机科学与技术2班教师:钱田芬时间: 2014年12月23日计算机学院(3)Month类,如表2-3所示:主要成员变量(属性)成员变量描述月月份显示按钮日历表变量类型intJTextFieldJButtonCalendarPad名称monthShowMonthbeforeMont、afterMonthcalendarpad表2-3:Month类表(4)NotePad类,如表2-3所示:主要成员变量(属性)成员变量描述变量类型名称文本输入区年、月、日按钮哈希表文本框日历表JTextAreaintJButtonHashtableJLabelCalendarPadtextYear、month、daySave、delete、queryhashtablelabelTextcalendarpad4.4测试与分析(1)初始化日历记事本页面如图3-1:图3-1:初始化日历记事本界面(2)向上翻年如图3-2所示:图3-2:向上翻年(3)向下翻年如图3-3所示:图3-3:向下翻年(3)向上翻月如图3-4所示:图3-4:向上翻月(4)向下翻月如图3-5所示:图3-5:向下翻月(4)保存日志如图3-6所示:图3-6:保存日志(5)删除日志如图3-7所示:图3-7:删除日志(6)查看日志如图3-8所示:图3-8:查看日志(7)查询日志如图3-9所示:图3-9:查询日志4.5程序代码(部分)CalendarPad.javaimport java.awt.BorderLayout;import java.awt.Color;import java.awt.Container;import java.awt.Font;import java.awt.GridLayout;import bel;import java.awt.event.MouseEvent;。
Java时间类-Calendar、Date、LocalDateLocalTime

Java时间类-Calendar、Date、LocalDateLocalTime1、Date 类 java.util.Date是⼀个“万能接⼝”,它包含⽇期、时间,还有毫秒数,如果你只想⽤java.util.Date存储⽇期,或者只存储时间,那么,只有你知道哪些部分的数据是有⽤的,哪些部分的数据是不能⽤的。
1.1 Date的构造⽅法 Date 是我们使⽤的最多的⼀个⽇期类,Date提供的构造⽅法在官⽅API中有⼀下⼏种: Date 类提供了多种构造⽅法,但是⽬前有很多⽅法都已经不建议使⽤public Date() {this(System.currentTimeMillis());}public Date(long date) {fastTime = date;}@Deprecatedpublic Date(int year, int month, int date) {this(year, month, date, 0, 0, 0);}@Deprecatedpublic Date(int year, int month, int date, int hrs, int min) {this(year, month, date, hrs, min, 0);}@Deprecatedpublic Date(int year, int month, int date, int hrs, int min, int sec)@Deprecatedpublic Date(String s) {this(parse(s));} ⽬前我们可以通过使⽤:Date date0 = new Date();Date date1 = new Date(time); 这两种⽅法创建对象的不同主要是通过指定的时间戳不同,通过设置Date 中的fastTime 进⾏设置Date 对象的时间。
除了使⽤构造⽅法获取实例,Date 还可以通过Instant来创建⼀个Date 实例:Instant instant = Instant.now();Date date = Date.from(instant); Instant 是Java 8 提供的新特性: 1.2 Date的常⽤⽅法 Date 类中,提供了常⽤的获取:年,⽉,⽇,时,分,秒等⽅法:Date date = new Date();int dates = date.getDate();int year = date.getYear();int month = date.getMonth();int day = date.getDay();int hours = date.getHours();int min = date.getMinutes();int second = date.getSeconds();long time = date.getTime();int times = date.getTimezoneOffset(); 输出结果:dates: 14year: 116month: 11day: 3hours: 15min: 8second: 29time: 1481699309422times: -480 读者可能会发现,这⾥的年份并不是我们想要的,这⾥主要是因为代码⽅法实现:我们可以看到,这⾥的getYear 并不是获取当前年份,⽽是获取到和1900年的差值,这⾥主要是因为JDK⽼版本遗留下来的问题,对于Date 中获取年⽉⽇的⽅法,现在已经不建议使⽤了。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
NIIT-2综合训练日历记事本专业计算机科学与技术学生姓名班级学号指导教师完成日期信息工程学院目录一、综合训练的目的 (1)二、综合训练的内容 (1)三、综合训练的具体实现 (1)四、综合训练的总结 (2)附录:源程序清单 (3)NIIT-2综合训练一、综合训练的目的(1) 进一步巩固所学的Java语言基础知识,达到熟练编写、运用的程度;(2) 锻炼自己的面向对象的程序设计思想,能够深刻认识面向过程与面向对象两种设计方法之间的区别;(3) 熟练掌握具体软件开发平台下(NetBeans)的动手能力,掌握Java应用程序设计的方法与技巧,实现从传统面向过程程序设计思维到面向对象程序设计思维的转型;(4) 初步了解MIS的概念与相关知识,具备独立设计、实现小型MIS系统的应用开发能力。
二、综合训练的内容题目:日历记事本三、综合训练的具体实现1.设计内容设计GUI界面的日历记事本。
系统将日历,记事本功能结合在一起,用户可以方便地在任何日期记录下有关内容或查看某个日期的记录内容。
2.设计要求1.系统界面的左侧是日历。
该日历可以按年份前后翻动,鼠标单击“上年”按钮时,当前日历的年份减一;当鼠标左键单击“下年”按钮,当前日历的年份加一。
2.该日历也可以在某年内按月前后翻动。
鼠标单击“上月”按钮时,当前日历的月份减一;当鼠标左键单击“下月”按钮,当前日历表的月份加一。
3.使用鼠标左键单击选定的日期,如已有记录内容,系统将弹出对话框提示该日历已有记录内容,并询问用户是否用记事本显示该内容。
4.用户选择具体日期后,可以将记事本的当前内容保存起来,形成日志。
3.总体设计本日历记事本程序共有4个java源文件。
CalendarPad.java该java文件生成的类负责创建本日历记事本程序主窗口。
该类含有main方法,程序从该类开始执行。
Year.java该文件负责创建管理年份的对象。
Momth.java该文件负责创建管理月份的类对象。
NotePad.java该文件负责创建记事本。
4.具体设计运行效果与程序发布1.将4个java文件保存到一个文件夹中。
将4个文件分别编译生成相应的字节码文件。
然后,用java解释器运行主类,效果如图:2.可以使用jar.exe把一些文件压缩成JAR文件,来发布我们的应用程序。
可以把本java应用程序中涉及到的类文件压缩成一个JAR文件,例如CalendarPad.jar.首先,用文本编辑器编写一个清单文件,然后,如下生成JAR文件:C:\notepad\jar cfm CalendarPad.jar moon.mf *.class其中,参数c表示要生成一个新的JAR文件;f表示要生成的JAR文件的名字;m表示清单文件的名字。
现在皆就可以将Calendar.Jar拷贝到任何一个安装了java 运行环境的计算机上,只要用鼠标双击文件就可以运行本java应用程序了。
另外创建一个帮助文件help.txt,内容如下:您可以用鼠标双击CalendarPad.jar或CalendarPad.bat来运行本软件,但是,如果您的计算机上安装了中文版WinRAR解压缩软件,并将.jar文件与该解压缩软件做了关联,那么,用鼠标双击CalendarPar.jar文件时,WinRAR解压缩软件会自动运行进行解压缩操作,这时您可以双击Calendar.Pad.bat来运行我们的软件。
最后,将.bat文件,.jar文件,帮助文件一同发布。
四、综合训练的总结经过一个学期的JA V A学习,我对JA V A编程有了一定的认识,在做这个课程设计的时候,刚开始感觉自己无从下手,不知道该怎么开始,很茫然。
最终利用网络资源和查阅图书馆的书籍,在傅老师和同学的指导和讨论下,经过一段时间终于完成了这个设计。
当程序运行结束看到弹出的日历记事本的界面时,感到很欣慰,虽然只是一个小小的东西,但却是自己起步的成就,从中学到了很多书本知识不能体现的东西,对JA V A的学习有了一定的兴趣。
也通过这次的程序设计感觉到自己平时对于编程实际操作的贫乏,没有把书本上的知识真正的掌握牢固。
以后要多动手做才会有收获。
附录:源程序清单CalendarPad.javaimport java.util.Calendar;import javax.swing.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.Hashtable;public class CalendarPad extends JFrame implements MouseListener{int year,month,day;Hashtable hashtable;File file;JTextField showDay[];JLabel title[];Calendar 日历;int 星期几;NotePad notepad=null;Month 负责改变月;Year 负责改变年;String 星期[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};JPanel leftPanel,rightPanel;public CalendarPad(int year,int month,int day){leftPanel=new JPanel();JPanel leftCenter=new JPanel();JPanel leftNorth=new JPanel();leftCenter.setLayout(new GridLayout(7,7));rightPanel=new JPanel();this.year=year;this.month=month;this.day=day;负责改变年=new Year(this);负责改变年.setYear(year);负责改变月=new Month(this);负责改变月.setMonth(month);title=new JLabel[7];showDay=new JTextField[42];for(int j=0;j<7;j++){title[j]=new JLabel();title[j].setText(星期[j]);title[j].setBorder(BorderFactory.createRaisedBevelBorder());leftCenter.add(title[j]);}title[0].setForeground(Color.red);title[6].setForeground(Color.blue);for(int i=0;i<42;i++){showDay[i]=new JTextField();showDay[i].addMouseListener(this);showDay[i].setEditable(false);leftCenter.add(showDay[i]);}日历=Calendar.getInstance();Box box=Box.createHorizontalBox();box.add(负责改变年);box.add(负责改变月);leftNorth.add(box);leftPanel.setLayout(new BorderLayout());leftPanel.add(leftNorth,BorderLayout.NORTH);leftPanel.add(leftCenter,BorderLayout.CENTER);leftPanel.add(new Label("请在年份输入框输入所查年份(负数表示公元前),并回车确定"),BorderLayout.SOUTH) ;leftPanel.validate();Container con=getContentPane();JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rightPanel);con.add(split,BorderLayout.CENTER);con.validate();hashtable=new Hashtable();file=new File("日历记事本.txt");if(!file.exists()){try{FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(hashtable);objectOut.close();out.close();}catch(IOException e){}}notepad=new NotePad(this);rightPanel.add(notepad);设置日历牌(year,month);addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){System.exit(0);}});setVisible(true);setBounds(100,50,524,285);validate();}public void 设置日历牌(int year,int month){日历.set(year,month-1,1);星期几=日历.get(Calendar.DAY_OF_WEEK)-1;if(month==1||month==2||month==3||month==5||month==7||month==8||month==10||month==12){排列号码(星期几,31);}else if(month==4||month==6||month==9||month==11){排列号码(星期几,30);}else if(month==2){if((year%4==0&&year%100!=0)||(year%400==0)){排列号码(星期几,29);}else{排列号码(星期几,28);}}}public void 排列号码(int 星期几,int 月天数){for(int i=星期几,n=1;i<星期几+月天数;i++){showDay[i].setText(""+n);if(n==day){showDay[i].setForeground(Color.green);showDay[i].setFont(new Font("TimesRoman",Font.BOLD,20));}else{showDay[i].setFont(new Font("TimesRoman",Font.BOLD,12));showDay[i].setForeground(Color.black);}if(i%7==6){showDay[i].setForeground(Color.blue);}if(i%7==0){showDay[i].setForeground(Color.red);}n++;}for(int i=0;i<星期几;i++){showDay[i].setText("");}for(int i=星期几+月天数;i<42;i++){showDay[i].setText("");}}public int getYear(){return year;}public void setYear(int y){year=y;notepad.setYear(year);}public int getMonth(){return month;}public void setMonth(int m){month=m;notepad.setMonth(month);}public int getDay(){return day;}public void setDay(int d){day=d;notepad.setDay(day);}public Hashtable getHashtable(){return hashtable;}public File getFile(){return file;}public void mousePressed(MouseEvent e){JTextField source=(JTextField)e.getSource();try{day=Integer.parseInt(source.getText());notepad.setDay(day);notepad.设置信息条(year,month,day);notepad.设置文本区(null);notepad.获取日志内容(year,month,day);}catch(Exception ee){}}public void mouseClicked(MouseEvent e){}public void mouseReleased(MouseEvent e){}public void mouseEntered(MouseEvent e){}public void mouseExited(MouseEvent e){}public static void main(String args[]){Calendar calendar=Calendar.getInstance();int y=calendar.get(Calendar.YEAR);int m=calendar.get(Calendar.MONTH)+1;int d=calendar.get(Calendar.DAY_OF_MONTH);new CalendarPad(y,m,d);}}Year.javaMonth.javaNote.javaYear.javaimport javax.swing.*;import java.awt.*;import java.awt.event.*;public class Year extends Box implements ActionListener{int year;int month;JTextField showYear=null;JButton 明年,去年;CalendarPad 日历;public Year(CalendarPad 日历){super(BoxLayout.X_AXIS);showYear=new JTextField(4);showYear.setForeground(Color.blue);showYear.setFont(new Font("TimesRomn",Font.BOLD,14));this.日历=日历;year=日历.getYear();明年=new JButton("下年");去年=new JButton("上年");add(去年);add(showYear);add(明年);showYear.addActionListener(this);去年.addActionListener(this);明年.addActionListener(this);}public void setYear(int year){this.year=year;showYear.setText(""+year);}public int getYear(){return year;}public void actionPerformed(ActionEvent e){if(e.getSource()==去年){year=year-1;showYear.setText(""+year);日历.setYear(year);日历.设置日历牌(year,日历.getMonth());}else if(e.getSource()==明年){year=year+1;showYear.setText(""+year);日历.setYear(year);日历.设置日历牌(year,日历.getMonth());}else if(e.getSource()==showYear){try{year=Integer.parseInt(showYear.getText());showYear.setText(""+year);日历.setYear(year);日历.设置日历牌(year,日历.getMonth());}catch(NumberFormatException ee){showYear.setText(""+year);日历.setYear(year);日历.设置日历牌(year,日历.getMonth());}}}}Month.java import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Month extends Box implements ActionListener{int month;JTextField showMonth=null;JButton 下月,上月;CalendarPad 日历;public Month(CalendarPad 日历){super(BoxLayout.X_AXIS);this.日历=日历;showMonth=new JTextField(2);month=日历.getMonth();showMonth.setEditable(false);showMonth.setForeground(Color.blue);showMonth.setFont(new Font("TimesRomn",Font.BOLD,16));下月=new JButton("下月");上月=new JButton("上月");add(上月);add(showMonth);add(下月);上月.addActionListener(this);下月.addActionListener(this);showMonth.setText(""+month);}public void setMonth(int month){if(month<=12&&month>=1){this.month=month;}else{this.month=1;}showMonth.setText(""+month);}public int getMonth(){return month;}public void actionPerformed(ActionEvent e){if(e.getSource()==上月){if(month>=2){month=month-1;日历.setMonth(month);日历.设置日历牌(日历.getYear(),month);}else if(month==1){month=12;日历.setMonth(month);日历.设置日历牌(日历.getYear(),month);}showMonth.setText(""+month);}else if(e.getSource()==下月){if(month<12){month=month+1;日历.setMonth(month);日历.设置日历牌(日历.getYear(),month);}else if(month==12){month=1;日历.setMonth(month);日历.设置日历牌(日历.getYear(),month);}showMonth.setText(""+month);}}}NotePad.java import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;public class NotePad extends JPanel implements ActionListener {JTextArea text;JButton 保存日志,删除日志;Hashtable table;JLabel 信息条;int year,month,day;File file;CalendarPad calendar;public NotePad(CalendarPad calendar){this.calendar=calendar;year=calendar.getYear();month=calendar.getMonth();day=calendar.getDay();;table=calendar.getHashtable();file=calendar.getFile();信息条=new JLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER);信息条.setFont(new Font("TimesRoman",Font.BOLD,16));信息条.setForeground(Color.blue);text=new JTextArea(10,10);保存日志=new JButton("保存日志") ;删除日志=new JButton("删除日志") ;保存日志.addActionListener(this);删除日志.addActionListener(this);setLayout(new BorderLayout());JPanel pSouth=new JPanel();add(信息条,BorderLayout.NORTH);pSouth.add(保存日志);pSouth.add(删除日志);add(pSouth,BorderLayout.SOUTH);add(new JScrollPane(text),BorderLayout.CENTER);}public void actionPerformed(ActionEvent e){if(e.getSource()==保存日志){保存日志(year,month,day);}else if(e.getSource()==删除日志){删除日志(year,month,day);}}public void setYear(int year){this.year=year;}public int getYear(){return year;}public void setMonth(int month){this.month=month;}public int getMonth(){return month;}public void setDay(int day){this.day=day;}public int getDay(){return day;}public void 设置信息条(int year,int month,int day){信息条.setText(""+year+"年"+month+"月"+day+"日");}public void 设置文本区(String s){text.setText(s);}public void 获取日志内容(int year,int month,int day){String key=""+year+""+month+""+day;try{FileInputStream inOne=new FileInputStream(file);ObjectInputStream inTwo=new ObjectInputStream(inOne);table=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();}catch(Exception ee){}if(table.containsKey(key)){String m=""+year+"年"+month+"月"+day+"这一天有日志记载,想看吗?";int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){text.setText((String)table.get(key));}else{text.setText("");}}else{text.setText("无记录");}}public void 保存日志(int year,int month,int day){String 日志内容=text.getText();String key=""+year+""+month+""+day;String m=""+year+"年"+month+"月"+day+"保存日志吗?";int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){try{FileInputStream inOne=new FileInputStream(file);ObjectInputStream inTwo=new ObjectInputStream(inOne);table=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();table.put(key,日志内容);FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(table);objectOut.close();out.close();}catch(Exception ee){}}}public void 删除日志(int year,int month,int day){String key=""+year+""+month+""+day;if(table.containsKey(key)){String m="删除"+year+"年"+month+"月"+day+"日的日志吗?";int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);if(ok==JOptionPane.YES_OPTION){try{FileInputStream inOne=new FileInputStream(file);ObjectInputStream inTwo=new ObjectInputStream(inOne);table=(Hashtable)inTwo.readObject();inOne.close();inTwo.close();table.remove(key);FileOutputStream out=new FileOutputStream(file);ObjectOutputStream objectOut=new ObjectOutputStream(out);objectOut.writeObject(table);objectOut.close();out.close();text.setText(null);}catch(Exception ee){}}}else{String m=""+year+"年"+month+"月"+day+"无日志记录";JOptionPane.showMessageDialog(this,m,"提示",JOptionPane.WARNING_MESSAGE);}}}。