用Java实现历记事本
java 注解实现操作日志详细记录
![java 注解实现操作日志详细记录](https://img.taocdn.com/s3/m/f9854a808ad63186bceb19e8b8f67c1cfad6eed7.png)
一、背景介绍在Java开发中,操作日志记录是非常重要的一项功能。
通过记录用户的操作行为,我们可以追踪用户的操作轨迹,了解系统的使用情况,排查问题,甚至进行安全审计。
而注解是Java中非常重要的特性之一,它可以用来给类、方法、字段等元素添加元数据信息,这为我们实现操作日志的详细记录提供了非常便利的方式。
二、注解的定义在我们开始讨论如何利用注解来实现操作日志详细记录之前,首先我们要了解一下注解的定义和使用。
在Java中,注解是元数据的一种形式,它可以用来提供对程序元素的修饰性信息。
在定义注解时,我们需要使用`interface`关键字来进行声明,并且可以在注解中定义一些属性,这些属性可以在使用注解的时候进行赋值。
三、注解的应用场景在实际的开发中,我们可以在很多地方使用注解来实现操作日志的详细记录,比如在Controller层的方法上、Service层的方法上、DAO层的方法上等。
通过在关键的操作点上添加注解,我们可以实现在用户的操作触发时自动记录相关的日志信息。
四、注解实现操作日志详细记录的步骤为了让大家更好地理解如何利用注解来实现操作日志的详细记录,接下来我们将具体介绍一下使用注解来记录操作日志的步骤。
a. 定义注解我们需要定义一个注解来标识需要记录操作日志的方法。
比如我们可以定义一个`OperationLog`注解。
在定义注解的时候,我们可以添加一些属性,比如操作类型、操作描述等。
b. 解析注解接下来,我们需要编写一个注解解析器,用来解析被`OperationLog`注解标注的方法。
在解析器中,我们可以使用Java的反射机制来获取方法上的注解信息,并根据注解的属性来记录日志。
c. 记录日志我们需要编写一个日志记录器,用来实际记录操作日志。
当用户触发了被`OperationLog`注解标注的方法时,我们可以在日志记录器中将相关的操作信息记录下来,比如操作时间、操作人、操作类型、操作描述等。
五、使用案例为了让大家更好地了解如何利用注解来实现操作日志的详细记录,我们接下来通过一个简单的使用案例来进行演示。
Java万年历源代码,可显示公历、农历、系统时间、国际时间
![Java万年历源代码,可显示公历、农历、系统时间、国际时间](https://img.taocdn.com/s3/m/204e7b2bdd36a32d737581f9.png)
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课程设计记事本设计报告](https://img.taocdn.com/s3/m/4df0d6dbc67da26925c52cc58bd63186bceb92cd.png)
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日历小程序](https://img.taocdn.com/s3/m/9fce2ac0710abb68a98271fe910ef12d2bf9a958.png)
java日历小程序简介:Java日历小程序是一个基于Java语言开发的工具,用于显示和管理日期和时间。
它提供了一种简单而直观的方式来查看、创建和编辑日历事件,并提供了一些额外的功能,如提醒、重复事件和时间段的计算等。
本文将详细介绍Java日历小程序的功能、使用方法和设计原理。
功能:1. 显示日历:Java日历小程序可以显示当前月份的日历,并以日、周或月的形式展示。
用户可以通过界面上的上下翻页按钮切换月份,方便查看不同日期的日历。
2. 创建和编辑事件:用户可以通过Java日历小程序创建新的日历事件,并为每个事件指定标题、日期、时间和地点等详细信息。
程序还提供了事件编辑功能,允许用户修改已有事件的信息。
3. 提醒功能:Java日历小程序可以设置事件的提醒功能,提醒用户在指定的时间前提醒。
用户可以选择在事件开始前几分钟、几小时或几天提醒,并可以自定义提醒方式,如弹窗、声音或邮件通知等。
4. 重复事件:用户可以为事件设置重复功能,使事件在指定的日期间隔内重复发生。
可以选择每天、每周、每月或每年重复,并可以设置重复的结束日期。
5. 时间段计算:Java日历小程序可以计算两个日期之间的时间段,如计算两个事件之间的天数、小时数或分钟数等。
用户可以选择计算方式,并获取精确的时间段结果。
使用方法:1. 下载和安装:用户可以从官方网站上下载Java日历小程序的安装包,然后按照安装向导进行安装。
安装完成后,用户可以在桌面或开始菜单中找到程序的快捷方式。
2. 打开程序:双击程序的快捷方式,Java日历小程序将启动并显示当前月份的日历。
用户可以通过界面上的按钮和菜单来使用各种功能。
3. 创建事件:用户可以点击界面上的“添加事件”按钮,弹出一个对话框,输入事件的详细信息,如标题、日期、时间和地点等。
点击“确定”按钮后,事件将被创建并显示在日历上。
4. 编辑事件:用户可以在日历上点击已有的事件,弹出一个对话框,允许用户修改事件的信息。
《Java》课程设计》记事本
![《Java》课程设计》记事本](https://img.taocdn.com/s3/m/ed6d2b1482c4bb4cf7ec4afe04a1b0717fd5b3ba.png)
《Java课程设计》记事本课程设计报告书目录一、设计课题二、设计目的三、操作环境四、设计场所(机房号、机器号或自己机器)五、设计过程(设计内容及主要程序模块)六、本次设计中用到的课程知识点(列出主要知识点)七、设计过程中遇到的问题及解决办法八、程序清单五、设计过程(设计内容及主要模块,不少于3000字)1.设计要求1)界面设计2)功能实现(1)文件菜单:新建、打开、保存、另存为、退出等。
(2)其中新建菜单项可以新建一个记事本程序;打开菜单项可以打开一个用户指定的文本文件,并将其内容显示在记事本的文本区域;保存和另存为菜单项可分别实现文件的保存和另存为3)编辑菜单:复制、剪切和粘贴等4)帮助菜单:软件版本信5)右键弹出快捷菜单2.总体设计1)功能模块图:图一功能模块图2)功能描述1、打开记事本。
首先是标准型的记事本,拥有文件、编辑。
格式和帮助。
如图1所示:图1标准型记事本界面2、在标准型的记事本界面中,进行的新建一个本件名字叫新记事本。
如图2记事本文件帮助新建打开保存另存为退出复制剪切粘贴编辑关于记事本右键快捷格式字体颜色图2新建记事本功能3、用打开文件打开刚刚新建的新记事本。
如图三所示。
图3—打开文件4、点击退出即可退出,如图4所示:图4—退出记事本5、点击帮助可以看到有关记事本的相关信息,其中有作者名、版本、许可条款、隐私声明等必要信息。
如图5所示:图5—帮助相关信息6、右键可实现复制、粘贴、剪切、清除等常用功能,方便用户可以快捷方便的使用记事本。
如图6所示:图6—右键功能7、编辑也可实现制、粘贴、剪切、清除等常用功能,方便用户选择自己适合的方式,自由选择方便的快捷方式使用。
如图7:图7—编辑八、程序清单package test;import java.io.File;import java.io.*;import java.awt.event.*;import java.awt.Toolkit;import java.awt.*;import javax.swing.*;import javax.swing.filechooser.*;public class Notebook extends JFrame implements ActionListener,ItemListener{ //组件创建JButton b_save,b_close; //按钮JTextArea textArea; //文本框File tempFile; //文件JPanel jp; //面板JMenu file,edit,style,help; //菜单JMenuItemf_new,f_open,f_save,f_close,f_saveas,e_copy, e_paste,e_cut,e_clear,e_selectAll,e_find,e_rep lace,s_font,s_color,h_editor,h_help; //菜单条JMenuBar jmb;JScrollPane jsp; //滚动面板JPopupMenu popUpMenu = new JPopupMenu(); //右键弹出式菜单JLabel stateBar;//标签JLabel jl,jj;JFileChooser jfc = new JFileChooser(); //文件选择JMenuItemje_copy,je_paste,je_cut,je_clear,je_selectAll,je _find,je_replace; //弹出式菜单条public Notebook(){jfc.addChoosableFileFilter(new FileNameExtensionFilter("文本文件(*.txt)","txt"));jmb = new JMenuBar();textArea = new JTextArea();jsp = new JScrollPane(textArea);file = new JMenu("文件");edit = new JMenu("编辑");style = new JMenu("格式");help = new JMenu("帮助");je_copy = new JMenuItem("复制(C) ");je_paste = new JMenuItem("粘贴(P) ");je_cut = new JMenuItem("剪切(X) ");je_clear = new JMenuItem("清除(D) ");je_selectAll = new JMenuItem("全选(A) ");je_find = new JMenuItem("查找(F) ");je_replace = new JMenuItem("替换(R) ");je_copy.addActionListener(this); //给弹窗式的各组件添加监听器je_paste.addActionListener(this);je_cut.addActionListener(this);je_clear.addActionListener(this);je_selectAll.addActionListener(this);je_find.addActionListener(this);je_replace.addActionListener(this);//给界面上方的菜单条添加监听器f_new = new JMenuItem("新建(N)");f_new.setAccelerator(KeyStroke.getKeyS troke('N',InputEvent.CTRL_MASK,false)); //设置带修饰符快捷键f_new.addActionListener(this);f_open = new JMenuItem("打开(O)");f_open.setAccelerator(KeyStroke.getKey Stroke('O',InputEvent.CTRL_MASK,false));f_open.addActionListener(this);f_save = new JMenuItem("保存(S)");f_save.setAccelerator(KeyStroke.getKey Stroke('S',InputEvent.CTRL_MASK,false));f_save.addActionListener(this);f_saveas = new JMenuItem("另存为");f_saveas.setAccelerator(KeyStroke.getKe yStroke(KeyEvent.VK_S,InputEvent.CTRL_ MASK|InputEvent.SHIFT_MASK));f_saveas.addActionListener(this);f_close = new JMenuItem("退出(W)");f_close.setAccelerator(KeyStroke.getKey Stroke('W',InputEvent.CTRL_MASK,false));f_close.addActionListener(this);e_copy = new JMenuItem("复制(C)");e_copy.setAccelerator(KeyStroke.getKey Stroke('C',InputEvent.CTRL_MASK,false));e_copy.addActionListener(this);e_paste = new JMenuItem("粘贴(V)");e_paste.setAccelerator(KeyStroke.getKeyStro ke('V',InputEvent.CTRL_MASK,false));e_paste.addActionListener(this);e_cut = new JMenuItem("剪切(X)"); e_cut.setAccelerator(KeyStroke.getKeyStroke ('X',InputEvent.CTRL_MASK,false));e_cut.addActionListener(this);e_clear = new JMenuItem("清除(D)");e_clear.setAccelerator(KeyStroke.getKeyStrok e('D',InputEvent.CTRL_MASK,false));e_clear.addActionListener(this);e_selectAll = new JMenuItem("全选(A)");e_selectAll.setAccelerator(KeyStroke.getKey Stroke('A',InputEvent.CTRL_MASK,false));e_selectAll.addActionListener(this);e_find = new JMenuItem("查找(F)");e_find.setAccelerator(KeyStroke.getKeyStrok e('F',InputEvent.CTRL_MASK,false));e_copy.addActionListener(this);e_replace = new JMenuItem("替换(R)");e_replace.setAccelerator(KeyStroke.getK eyStroke('R',InputEvent.CTRL_MASK,false)) ;e_replace.addActionListener(this);s_font = new JMenuItem("字体(T)");s_font.setAccelerator(KeyStroke.getKeyStrok e('T',InputEvent.CTRL_MASK,false));s_font.addActionListener(this);s_color = new JMenuItem("颜色(C)...");s_color.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_C,InputEvent.CTRL_MAS K | InputEvent.SHIFT_MASK));s_color.addActionListener(this);h_editor = new JMenuItem("关于记事本");h_editor.setAccelerator(KeyStroke.getKeyStro ke(KeyEvent.VK_E,InputEvent.CTRL_MAS K));h_editor.addActionListener(this);h_help = new JMenuItem("帮助信息(H)");h_help.setAccelerator(KeyStroke.getKeyStrok e(KeyEvent.VK_I,InputEvent.CTRL_MASK) );h_help.addActionListener(this);//添加右键弹出式菜单popUpMenu.add(je_copy);popUpMenu.add(je_paste);popUpMenu.add(je_cut);popUpMenu.add(je_clear);popUpMenu.addSeparator();popUpMenu.add(je_selectAll);popUpMenu.add(je_find);popUpMenu.add(je_replace);//编辑区鼠标事件,点击右键弹出"编辑"菜单textArea.addMouseListener(new MouseAdapter(){public void mouseReleased(MouseEvent e) {if(e.getButton() == MouseEvent.BUTTON3)popUpMenu.show(e.getComponent(), e.getX(), e.getY());} //e.getComponent()和textArea具有同等效果public void mouseClicked(MouseEvent e){if(e.getButton() == MouseEvent.BUTTON1)popUpMenu.setVisible(false);}});this.setJMenuBar(jmb);this.setTitle("记事本程序");file.add(f_new); //添加文件菜单组件file.add(f_open);file.addSeparator(); //加分隔线file.add(f_save);file.add(f_saveas);file.addSeparator();file.add(f_close);edit.add(e_copy); //添加编辑菜单组件edit.add(e_paste);edit.add(e_cut);edit.add(e_clear);edit.addSeparator();edit.add(e_selectAll);edit.add(e_find);edit.add(e_replace);style.addSeparator();style.add(s_font);style.add(s_color);jmb.add(file); //添加格式菜单组件jmb.add(edit);jmb.add(style);jmb.add(help);help.add(h_editor); //添加帮助菜单组件help.add(h_help);//textArea.setWrapStyleWord(true); //设置在单词过长的时候是否要把长单词移到下一行。
日历源代码——java
![日历源代码——java](https://img.taocdn.com/s3/m/568f36c56137ee06eff91886.png)
日历源代码——java//import java.sql.Date;import java.util.Calendar;import java.util.Date;import java.util.GregorianCalendar;import java.util.Locale;public class GregorianCalendar日历 {public static void main(String[] args) { //设置不同地区Locale.setDefault();//创建当前日历对象GregorianCalendar now = new GregorianCalendar();//从当前时期对象是取出时间日期对象//编辑错误:Type mismatch: cannot convert from java.util.Date to java.sql.DateDate date = now.getTime();//将时间日期对象按字符形式打印System.out.println(date.toString());//重新将时间对象设置到日期对象中now.setTime(date);//从当前日期对象是取出当前月份、日期int today =now.get(Calendar.DAY_OF_MONTH);int month = now.get(Calendar.MONTH);//获取本月开始日期now.set(Calendar.DAY_OF_MONTH, 1);//获取本月开始日期在一周中的编号int week = now.get(Calendar.DAY_OF_WEEK);//打印日历头并换行设置当前月中第一天的开始位置System.out.println("星期日星期一星期二星期三星期四星期五星期六");//设置当前月中第一天的开始位置for( int i = Calendar.SUNDAY; i < week; i++){ System.out.print(" ");//按规格打印当前月的日期数字while(now.get(Calendar.MONTH) ==month){//取出当前日期int day =now.get(Calendar.DAY_OF_MONTH);//设置日期数字小于10与不小于10两种情况的打印规格if(day < 10){//设置当前日期的表现形式if(day == today)System.out.print(" <" + day + "> ");elseSystem.out.print(" " + day + " ");}else{//设置当前日期的表现形式if(day == today)System.out.print(" <" + day + "> ");elseSystem.out.print(" " + day + " ");}//设置什么时候换行if(week == Calendar.SATURDAY)System.out.println();//设置日期与星期几为下一天now.add(Calendar.DAY_OF_MONTH, 1);week = now.get(Calendar.DAY_OF_WEEK);}}}}。
记事本程序java课程设计
![记事本程序java课程设计](https://img.taocdn.com/s3/m/3b5562466ad97f192279168884868762caaebbeb.png)
记事本程序java课程设计一、教学目标本课程旨在通过记事本程序的设计与实现,让学生掌握Java编程的基本语法、面向对象编程思想,以及常用数据结构的使用。
在知识目标上,要求学生能够熟练运用Java语言编写简单的记事本程序,理解并应用面向对象编程的基本概念,如封装、继承和多态。
在技能目标上,培养学生分析问题、解决问题的能力,以及良好的编程习惯。
在情感态度价值观目标上,激发学生对计算机科学的兴趣,培养学生的创新意识和团队协作精神。
二、教学内容本课程的教学内容主要包括Java语言基础知识、面向对象编程、常用数据结构、记事本程序设计等。
具体安排如下:1.Java语言基础知识:介绍Java编程语言的基本语法、数据类型、运算符、控制结构等。
2.面向对象编程:讲解类与对象、封装、继承和多态等概念,并引导学生通过实例掌握面向对象编程的方法。
3.常用数据结构:介绍数组、链表、栈、队列等数据结构的基本原理和应用。
4.记事本程序设计:引导学生运用所学知识编写一个简单的记事本程序,掌握文件操作、文本编辑等技能。
三、教学方法为了提高教学效果,本课程将采用多种教学方法相结合的方式,如讲授法、案例分析法、实验法等。
在教学过程中,教师将引导学生通过查阅教材、观看教学视频、编写代码和参与讨论,从而深入理解Java编程知识和记事本程序设计技巧。
同时,鼓励学生进行自主学习和团队合作,培养学生的创新意识和解决问题的能力。
四、教学资源为了支持教学内容和教学方法的实施,我们将准备以下教学资源:1.教材:《Java编程思想》等。
2.参考书:《Java核心技术》、《Java Web开发》等。
3.多媒体资料:教学视频、PPT课件等。
4.实验设备:计算机、网络设备等。
通过以上教学资源的支持,学生将能够更好地学习Java语言和记事本程序设计,提高自己的编程技能。
五、教学评估本课程的教学评估将采用多元化的评价方式,以全面、客观、公正地评估学生的学习成果。
JAVA--简单记事本源代码
![JAVA--简单记事本源代码](https://img.taocdn.com/s3/m/59dab440777f5acfa1c7aa00b52acfc789eb9f8a.png)
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万年历程序代码
![java万年历程序代码](https://img.taocdn.com/s3/m/8ff555c34028915f804dc2d4.png)
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开发日历记事本
![Java开发日历记事本](https://img.taocdn.com/s3/m/c130e2e6102de2bd96058815.png)
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日历之GUI界面化
![java日历之GUI界面化](https://img.taocdn.com/s3/m/d3d08a88d1f34693daef3e65.png)
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); } }
} for(int i=0;i<星期几;i++) { showDay[i].setText(""); } for(int i=星期几+月天数;i<42;i++) { showDay[i].setText(""); }
} if(i%7==0) { showDay[i].setForeground(Color.red); } n++;
} 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);
java编程记事本代码
![java编程记事本代码](https://img.taocdn.com/s3/m/ad8992f402020740bf1e9ba4.png)
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,"文件的文字已经改变。
日历记事本-JAVA课程设计..
![日历记事本-JAVA课程设计..](https://img.taocdn.com/s3/m/6d37433858fb770bf78a5593.png)
沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学图7 删除后页面图4.设计体会经过几天的努力,参考了一些书和网上的资料,完成了一个日历记事本的设计。
由于只学过一学期的Java课程,知识掌握的有限,所以此程序不是特别复杂。
在这个过程中,在把书本上的知识给系统的复习了一下的同时,同时也发现了自己的太多不足,对JA V A语言整体知识构架不够熟悉,不能灵活地运用所学的知识点。
自己的编程方式也不是太标准,经常出现代码写错而调试很久的低级错误情况出现。
通过这次课程设计,我明白了编写程序,不仅要求对课本知识有较深刻的了解,同时要求程序设计者有较强的思维和动手能力。
还要熟悉常用的编程技巧和编程思想,不能只关心程序的运行结果,更要注重程序代码的结构,编程者更要有严谨地态度。
本次课程设计不仅巩固了以前所学的知识,还有通过设计过程中大量地查阅网络文章,对一些关键知识点逐个地了解并解决相关问题。
所以网络这个强大的工具,确实是我们学习之中可以借助的一个很好的帮手。
网络是我们学习的最好的老师之一。
有问题,问网络,是一个很好的习惯。
因此学到了不少书本上没有的知识;学到了很多java编程知识。
可以说它给了我一次自我评估的机会。
通过设计让我知道了那些方面我还是有欠缺的,促使我花时间弥补。
总之,本次课程设计收获颇丰。
5.参考文献沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学沈阳大学。
JAVA课程设计报告模板11
![JAVA课程设计报告模板11](https://img.taocdn.com/s3/m/27641d40c4da50e2524de518964bcf84b9d52dc1.png)
一、设计分析题目: 日历记事本系统将日历和记事本结合在一起,可以方便地保存、查看日志, 即在任何日期记载下有关内容或查看某个日期记载的内容, 要求如下:(1)显示信息:用户可以向前翻页查询前一个月的日期, 也可以向后翻页查询下一个月的日期。
(2)定时提醒:用户可以针对某一天来添加, 删除和编辑这一天的日程提醒信息, 当系统时间和提醒时间相吻合时, 给出具有提示信息的对话框。
(3)查询信息: 用户可以查询到某个月的所有的提示信息。
分析:可以将整个程序分为三个模块: 日历模块、记事本模块、闹铃模块。
日历模块负责显示信息功能。
定义一个日历实体类, 用于保存某年某月下的一个月的日期信息。
然后在视图中用个JPanel用于存放日历的视图和一些相关按钮。
然后将相关功能实现后, 建立按钮的监听事件, 以在按钮被按下的时候响应。
记事本模块负责查询信息以及定时提醒中的添加、删除和编辑某一天的日程提醒信息的功能。
定义一个提示信息实体类, 用于保存提示信息。
定义一个提示信息的工具类, 用于对提示信息进行各项操作, 如:增加、删除、查询等。
在视图中, 用个JList与提示信息实体类关联, 用于显示提示信息的列表, 并且可以选中后对提示信息的具体内容修改。
然后提示信息中的具体内容用一个JTextArea来读取、显示和保存。
闹铃模块负责定时提醒中的提醒功能。
定义一个闹钟类, 用于启动后一直检索当前提示信息, 看有没有需要提示的。
由于本闹钟会有声音提示, 所以需要定义一个音乐播放类负责声音提示。
然后将声音播放类和闹钟类关联, 主要负责闹铃模块的是闹钟类。
二、程序结构三、各模块的功能及程序说明日历模块:选定年份与月份后, 会显示该年该月的日期排布。
然后该模块具有向前/向后调整一年、向前/向后调整一月的按钮, 点击按钮可以实现相应的功能。
并且, 利用JCombox提供可以直接选择的年份列表、月份列表, 选中后会相应刷新日历视图。
记事本模块:该模块有添加、删除、修改、查询日程提示信息的功能。
java日历记事本(无敌版带提醒功能调整时区更换图片铃声功能)
![java日历记事本(无敌版带提醒功能调整时区更换图片铃声功能)](https://img.taocdn.com/s3/m/80afc3b4a8114431b80dd857.png)
装订线北京师范大学2015~2016学年春季学期期末Java程序设计作业试卷课程名称: Java程序设计任课教师姓名:孙一林卷面总分: 100 分考试时长:分钟考试类别:闭卷□开卷其他□院(系):信息科学与技术学院专业:计算机科学与技术年级: 2014 姓名:刁诗哲学号:阅卷教师(签字):评价准则:(1)应用程序设计思想………………………………………………… ≤ 20% (2)程序结构表述……………………………………………………… ≤ 20% (3)调试、运行、结果………………………………………………… ≤ 20% (4)报告+程序文档………………………………………………………≤ 20% (5)应用程序展示(5分钟讲解与演示)……………………………≤ 10% (6)应用程序难易度……………………………………………………≤ 10%设计要求:选择一题,按自己理解设计程序,在报告(该试卷首页为报告第1页,文件名及格式为:*.doc或*.docx,* = 学号 + 姓名,报告为必要项)中给出设计思路、程序结构、调试、模拟运行、结果等说明内容,提交作业(设计、调试、运行、结果):报告+程序所有(源程序、类、打包等)文件的压缩文档(学号 + 姓名)。
设计题目难易度依照题号顺序由小到大。
多功能日历记事本一、整体介绍1.外观显示日历外观如下图所示,全局大体分为四个部分:左上,左下,右上,右下。
最上面是标题栏,显示该程序的名称,如我的程序显示的为“刁诗哲的日历”。
标题栏下方为菜单栏,菜单栏目前有两个菜单,分别是“功能设置”和“关于”。
左上部分为日历界面,显示一个万年历,用户可以在输入框中输入所查年份和月份,按下回车后自动跳转到该月。
左下部分是显示图片部分,用户可以自主设置自己喜欢的图片,设置这一功能主要是给用户提供个性化的用户体验,可以根据自己的喜好设置喜爱的图片,比如放置一个名人座右铭可以勉励自己在学业上不断进步。
日历记事本
![日历记事本](https://img.taocdn.com/s3/m/2e78d06fddccda38376baf6e.png)
课程设计报告课程:面向对象程序设计学号:姓名:班级:计算机科学与技术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学习案例-实现日记本功能
![Java学习案例-实现日记本功能](https://img.taocdn.com/s3/m/ec08f63acd7931b765ce0508763231126edb77cc.png)
日记本【任务介绍】1.任务描述编写一个日记本功能的程序,使用字节流经日记的具体信息记录在本地的txt文件中。
当用户输入日记的特定内容后,会将输入的内容保存至本地的txt文件中。
需要输入的内容包括“姓名”,“天气”、“标题”、“内容”的数据。
保存的时候需要判断本地是否存在文件,如果存在则追加,不存在则新建。
文件命名格式为“黑马日记本”加上“.txt”后缀,如“黑马日记本.txt”2.运行结果任务运行结果如图7-1所示。
图7-2 运行结果运行结束后在本地生成一个“黑马日记本.txt”文件,如图7-2所示。
图7-2 黑马日记本.txt【任务目标】●学会分析"日记本小功能"程序的实现思路。
●根据思路独立完成"日记本小功能"的源代码编写、编译及运行。
●掌握字节流操作本地文件的方法。
●掌握ArrayList和StringBuffer的使用,以及异常的处理。
【实现思路】(1)为方便保存日记的相关信息,可以将日记信息封装成一个实体类。
(2)用户编写日记时,首先创建一个集合用于存放日记,然后用户依次填写的内容为“姓名”,“天气”、“标题”和“内容”,并将这些内容存放在集合中,再将实体类保存到txt文件中。
(3)查询日记时,使用字节流的读取实现控制台打印日记信息。
(4)将日记信息写入到txt文件之前,需先拼凑好txt文件名,再判断本地是否已存在此文件,这里可通过输入流尝试获取此文件的字节流,如果获取成功,则证明这个文件已存在,那么就通过输出流向文件末尾追加日记信息,如果获取失败,即异常,说明之前并没有生成日记信息,则需要新建此文件。
【实现代码】日记小功能的实现代码,如文件7-1所示。
(1)将日记信息封装成一个实体类Diary,具体如文件7-1所示。
文件7-1 Diary.java1 package chapter0703;2 public class Diary {3 String time; //时间4 String name; //姓名5 String weather;//天气6 String title;//标题7 String content;//内容8 public Diary(String time, String name, String weather, String title,9 String content) {10 this.time = time;11 = name;12 this.weather = weather;13 this.title = title;14 this.content=content;15 }16 }在文件7-1中,第3-7行代码定义了用于标识日记信息的各个字段,第8-14行代码重新了toString()方法。
java记事本源代码
![java记事本源代码](https://img.taocdn.com/s3/m/f9d32a01de80d4d8d15a4f83.png)
JMenuItem m13=new JMenuItem("另保存为 ");
m13.addActionListener(this);
JMenuItem m14=new JMenuItem("退出 ");
m14.addActionListener(this);
{
myfr fr=new myfr("JAVA记事本");
fr.setSize(560,395);
}
}
///////////////////////////myfr主窗体类//////////////////////////////////////
class myfr extends JFrame implements ActionListener
JTextArea txt1; //主输入文本区
File newfiles;
JPopupMenu popm; //弹出菜单声明
//JMenu m1,m2,m3,m4,m5,m6; //各菜单项
JMenu m1, m2, m3;
JMenuItem m26,m271,m34,p_copy,p_cut,p_paste,p_del;
replb.addActionListener(this);
mainpane=(JPanel)this.getContentPane();
mainpane.setLayout(new BorderLayout());
txt1=new JTextArea("",13,61);
m21.setAccelerator(keycopy);
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
public class Year extends Box implements ActionListener {
int year;
JTextField showYear=null;
JButton Year1,Year2;
CalendarPad CAL;
public Year(CalendarPad CAL) {
}
public void setYear(int y) {
year=y;
(year);
}
public int getMonth() {
return month;
}
public void setMonth(int m) {
month=m;
(month);
}
public int getDay() {
return day;
JTextField source=(JTextField)();
try {
day=());
(day);
(year,month,day);
(null);
}
catch(Exception ee) {}
}
public void mouseClicked(MouseEvent e){}
public void mouseReleased(MouseEvent e){}
if(n==day) {
showDay[i].setForeground;
showDay[i].setFont(new Font("TimesRoman",,20));
}
else {
showDay[i].setFont(new Font("TimesRoman",,12));
showDay[i].setForeground;
(1) 对日期的设置和获取,设置信息条,对文本框进行设置,保存日志、删除日志和读取日志按钮的事件实现。
(2)保存日志按钮事件实现如下:
(3)读取日志按钮事件实现如下:
(4.)删除日志按钮事件实现如下:
3Year类
(1)输入年份可以实现输出,给上下年按钮设置监视器,对上下年按钮事件的实现。
(2)其结果如下:
News=new JLabel(""+year+"年"+month+"月"+day+"日",;
(new Font("TimesRoman",,20));
text=new JTextArea(10,15);
setLayout(new BorderLayout());
JPanel pSouth=new JPanel();
(2)当左键单击日历上的日期时,如要获取该日期,可通过处理该组件上的鼠标事件来实现。
4.实验步骤、实施过程、关键代码、实验结果及分析说明等
1.CalendarPad类
(1)进行整体布局,建立日历记事本文件,设置日历卡,把日期按星期顺序排列,并用窗口监视器实现。
(2)用窗口监视器实现,结果如下:
2.Notepad类
(year);
ChangeMonth=new Month(this);
(month);
title=new JLabel[7];
showDay=new JTextField[42];
for(int j=0;j<7;j++) {
title[j]=new JLabel();
title[j].setText(week[j]);
4.Month类
(1)设置上下月监视器,对上下月按钮的事件实现,区分闰年和平年,对天数不同的月份进行分类。
(2)其结果如下:
(续上页,可加页)
5各个类的源代码如下:
CalendarPad类:
;
import .*;
import .*;
public class CalendarPad extends JFrame implements MouseListener,ActionListener {
ObjectOutputStream objectOut=new ObjectOutputStream(out);
(hashtable);
();
();
}
catch(IOException e){}
}
setCalendar(year,month);
addWindowListener(new WindowAdapter() {etText(""+n);
add(Month1);
add(showMonth);
add(News,;
add(pSouth,;
add(new JScrollPane(text),;
}
public void setYear(int year) {
=year;
}
public int getYear() {
return year;
}
public void setMonth(int month) {
title[j].setBorder());
title[j].setForeground;
(title[j]);
}
for(int i=0;i<42;i++) {
showDay[i]=new JTextField();
showDay[i].addMouseListener(this);
showDay[i].setEditable(false);
Month ChangeMonth;
Year ChangeYear ;
String week[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
JPanel leftPanel,rightPanel;
public CalendarPad(int year,int month,int day) {
用Java实现日历记事本
1.实验目的
掌握RandomAccessFile类的使用;掌握字符输入、输出流和缓冲输入、输出流的使用。
2.实验要求
实验前,应事先熟悉相关知识点,拟出相应的实验操作步骤,明确实验目的和要求;实验过程中,服从实验指导教师安排,遵守实验室的各项规章制度,爱护实验仪器设备;实验操作完成后,认真书写实验报告,总结实验经验,分析实验过程中出现的问题。
int year,month,day;
Hashtable hashtable;
JButton Save,Delete,Read;
File file;
JTextField showDay[];
JLabel title[];
Calendar Date;
int Weekday;
NotePad notepad=null;
public void mouseExited(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public static void main(String args[]) {
Calendar calendar=();
int y=;
int m=+1;
int d=;
new CalendarPad(y,m,d);
}
}
NotePad类
;
import .*;
import .*;
import .*;
public class NotePad extends JPanel implements ActionListener {
JTextArea text;
Hashtable table;
}
public void setDay(int d) {
day=d;
(day);
}
public Hashtable getHashtable() {
return hashtable;
}
public File getFile() {
return file;
}
public void mousePressed(MouseEvent e) {
3.实验内容
编程实现日历记事本。具体要求如下:
(1)该日历可以通过在文本框中输入年份和月份设置日期,也可按年前后翻动,用鼠标左键单击“上年”和“下年”按钮,将当前日历的年份减一和加一。还可以在某年内按月前后翻动,用鼠标左键单击“上月”和“下月”按钮,将日历的月份减一和加一。
(2)左键单击日历上的日期,可以通过右侧的记事本(文本区)编辑有关日志,并将日志保存到一个文件,该文件的名字是由当前日期组成的字符序列。用户可以读取、删除某个日期的日志,也可以继续向某个日志添加新的内容。在保存、删除和读取日志时都会先弹出一个确认对话框,以确认保存、删除和读取操作。
(""+year+"年"+month+"月"+day+"日");
}
public void setText(String s) {
(s);
}
public void actionPerformed(ActionEvent e) {}
public void Save(File file,int year,int month,int day) {;
}
n++;