Calendar日历小程序
//有待完善,有点bug
package com.sunshine.framework.calendar.model;
import java.util.Calendar;
/**
*
* <p>
* 描述该类情况 {@link 代表跟谁有关系}
* </p>
*
* @author 王超
* @since 1.0
* @date 2016年10月20日 下午8:19:15
* @see 新建|修改|放弃
* @see com.sunshine.framework.calendar.model.CalendarBean
*/
public class CalendarBean {
String day[];
int year = 2005, month = 0;
public String[] getCalendar() {
String a[] = new String[42];
// 获取日历的实例对象
Calendar date = Calendar.getInstance();
// 设置日历日期
date.set(this.year, this.month - 1, 1);
// 获取周数
int week = date.get(Calendar.DAY_OF_WEEK);
int day = 0;
// 判断大月份
if (this.month == 1 || this.month == 3 || this.month == 5 || this.month == 7 || this.month == 8
|| this.month == 10 || this.month == 12) {
day = 31;
}
// 判断小月
if (this.month == 4 || this.month == 6 || this.month == 9 || this.month == 11) {
day = 30;
}
// 单独判断2月
if (this.month == 2) {
// 判断是闰年 能被4或400整除 但不能被100整除
if ((this.year % 4 == 0) || (this.year % 100 != 0) || (this.year % 400 == 0)) {
day = 29;
} else {
day = 28;
}
}
for (int i = week, n = 1; i < week + day; i++) {
a[i] = String.valueOf(n);
n++;
}
return a;
}
public int getMonth() {
return this.month;
}
public int getYear() {
return this.year;
}
public void setMonth(int month) {
this.month = month;
}
public void setYear(int year) {
this.year = year;
}
}
package com.sunshine.framework.calendar;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.sunshine.framework.calendar.model.CalendarBean;
/**
*
* <p>
* 描述该类情况 {@link 代表跟谁有关系}
* </p>
*
* @author 王超
* @since 1.0
* @date 2016年10月20日 下午8:41:58
* @see 新建|修改|放弃
* @see com.sunshine.framework.calendar.CalendarFrame
*/
public class CalendarFrame extends JFrame implements ActionListener {
/***/
private static final long serialVersionUID = 1L;
JButton button = new JButton();
CalendarBean calendar;
JLabel labelDay[] = new JLabel[42];
JLabel lbl1 = new JLabel("请输入年份:");
JLabel lbl2 = new JLabel("");
String name[] = { "日", "一", "二", "三", "四", "五", "六" };
JButton nextMonth, previousMonth;
JLabel showMessage = new JLabel("", JLabel.CENTER);
JTextField text = new JTextField(10);
JButton titleName[] = new JButton[7];
int year = 1996, month = 1;
public CalendarFrame() {
JPanel pCenter = new JPanel();
// 将pCenter的布局设置为7行7列的GridLayout布局
pCenter.setLayout(new GridLayout(7, 7));
// pCenter添加组件titleName[i]
for (int i = 0; i < 7; i++) {
// 把星期值存入到titleName数组里
this.titleName[i] = new JButton(this.name[i]);
}
// pCenter添加组件labelDay[i]
for (int i = 0; i < 42; i++) {
this.labelDay[i] = new JLabel("", JLabel.CENTER);
pCenter.add(this.labelDay[i]);
}
this.text.addActionListener(this);
this.calendar = new CalendarBean();
this.calendar.setYear(this.year);
this.calendar.setMonth(this.month);
String day[] = this.calendar.getCalendar();
for (int i = 0; i < 42; i++) {
this.labelDay[i].setText(day[i]);
}
this.nextMonth = new JButton("下月");
this.previousMonth = new JButton("上月");
this.button = new JButton("确定");
// 注册监听器
this.nextMonth.addActionListener(this);
this.previousMonth.addActionListener(this);
this.button.addActionListener(this);
JPanel pNorth = new JPanel(), pSouth = new JPanel();
pNorth.add(this.showMessage);
pNorth.add(this.lbl2);
pNorth.add(this.previousMonth);
pNorth.add(this.nextMonth);
pNorth.add(this.lbl1);
pNorth.add(this.text);
pNorth.add(this.button);
this.showMessage.setText("日历:" + this.calendar.getYear() + "年" + this.calendar.getMonth() + "月");
ScrollPane scrollPane = new ScrollPane();
scrollPane.add(pCenter);
// 窗口添加scrollPane在中心区域
add(scrollPane, BorderLayout.CENTER);
// 窗口添加pNorth 在北面区域
add(pNorth, BorderLayout.NORTH);
// 窗口添加pSouth 在南区域。
add(pSouth, BorderLayout.SOUTH);
}
/*
* (方法重写)
*
* @see
* java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == this.nextMonth) {
this.month = this.month + 1;
if (this.month > 12) {
this.month = 1;
}
this.calendar.setMonth(this.month);
String day[] = this.calendar.getCalendar();
for (int i = 0; i < 42; i++) {
this.labelDay[i].setText(day[i]);
}
} else if (e.getSource() == this.previousMonth) {
this.month = this.month - 1;
if (this.month < 1) {
this.month = 12;
}
this.calendar.setMonth(this.month);
String day[] = this.calendar.getCalendar();
for (int i = 0; i < 42; i++) {
this.labelDay[i].setText(day[i]);
}
} else {
this.month = this.month + 1;
if (this.month > 12) {
this.month = 1;
}
this.calendar.setYear(Integer.parseInt(this.text.getText()));
String day[] = this.calendar.getCalendar();
for (int i = 0; i < 42; i++) {
this.labelDay[i].setText(day[i]);
}
}
this.showMessage.setText("日历:" + this.calendar.getYear() + "年" + this.calendar.getMonth() + "月");
}
}
package com.sunshine.framework.calendar;
import javax.swing.JFrame;
import javax.swing.UIManager;
/**
*
* <p>
* 描述该类情况 {@link 代表跟谁有关系}
* </p>
*
* @author 王超
* @since 1.0
* @date 2016年10月20日 下午9:34:15
* @see 新建|修改|放弃
* @see com.sunshine.framework.calendar.CalendarMain
*/
public class CalendarMain {
public static void main(String[] args) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
CalendarFrame frame = new CalendarFrame();
frame.setBounds(100, 100, 360, 300);
frame.setTitle("日历小程序");
// 窗体居中显示
frame.setLocationRelativeTo(null);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
转载于:https://www.cnblogs.com/qingtianBKY/p/5988783.html
Calendar日历小程序相关推荐
- java gui 日历_Java实现简单日历小程序 Java图形界面小日历开发
今天给大家介绍一下如何用Java swing开发一款简单的小日历,下面我们来看代码: 首先创建一个CalendarBean类,用于基本的日期计算: package other1; import jav ...
- Java实现简单的日历小程序之Java图形界面开发小日历
首先创建一个CalendarBean类,用于基本的日期计算: package other1;import java.util.Calendar; public class CalendarBean { ...
- java 日历界面_Java实现简单日历小程序 Java图形界面小日历开发
今天给大家介绍一下如何用java swing开发一款简单的小日历,下面我们来看代码: 首先创建一个calendarbean类,用于基本的日期计算: package other1; import jav ...
- java简易日历程序报告_Java实现简单日历小程序 Java图形界面小日历开发
今天给大家介绍一下如何用Java swing开发一款简单的小日历,下面我们来看代码: 首先创建一个CalendarBean类,用于基本的日期计算: package other1; import jav ...
- 编程日历小程序,对小程序云开发和生成分享海报的实践
1.起源 朋友圈晒的很多的一本日历书<了不起的程序员 2021>,我也买了,很厚,纸质书嘛,现在已经很少看了,加上这是一本日历书,希望是每天都打开看.可实际上的情况是,要么忘记看今天的内容 ...
- 又发福利!日历小程序源码
继续分享99个小程序源码. 本期分享的小程序是是一个日历小程序,可以实现上下翻页的.这个小程序是单机版的,导入开发工具就可以运行,开发者可以在此基础上根据业务场景二次开发. 如上图所示,可以展示星期几 ...
- 不知道有哪些日历小程序的,看这里!
最近很多小伙伴都在问我哪些天气小程序是比较好用的,还有不知道有哪些日历小程序的,看这里啦! 一.天天预约日历 天天预约日历简单的来说就是一个备忘录,您只需要在上面挑选一个日期,选择好时间,填上您那天想 ...
- python日历小程序_python写的日历小程序
查看: 14785|回复: 262 [作品展示] python写的日历小程序 电梯直达 发表于 2013-8-19 21:38:32 | 只看该作者 |倒序浏览 |阅读模式 马上注册,结交更多好友,享 ...
- 为Linux Mint Cinnamon的日历小程序增加中国农历显示以及其它部分参数优化
我最近使用Linux Mint Xfce的时间比较多,这个操作系统虽然运行效率高,占用资源少,但是感觉Xfce桌面稳定性还存在不足,经常出现莫名其妙的画面抖动及部分区域出现花屏的现象,还容易出现使用者 ...
最新文章
- 数据架构简史:转换中的范式
- 设计模式------代理模式
- 信息学奥赛一本通1349-最优布线问题
- 虚函数和纯虚函数的区别是什么?
- 20 FI配置-财务会计-定义税务科目
- mybatis多数据源配置_随笔:springboot+mybatis 配置双数据源
- 2020 年了,不知道这些还怎么做区块链工程师?
- 网购工具软件chrome扩展插件大推荐
- 关于Cookie在顶级域名、二级域名和三级域名之间共享的情况
- 金彩教育:选择关键词要参考哪些数据
- 五一劳动节,讲讲NEO智能合约的调试
- Android Studio 部分查找快捷键
- 棕榈油跌停见顶,铁矿石认沽上涨,YP05惊天大反弹2022.3.14
- 6个非常实用的 Python 代码块,适合收藏~
- 【DB笔试面试606】在Oracle中,coe_xfr_sql_profile.sql脚本的作用是什么?
- Yuki Chan全自动渗透测试工具的安装及使用
- IC卡,ID卡,HID卡外观和介绍
- 提交一个骗子喵喵源码站
- 金融银行产品培训推广PPT模板-优页文档
- Xposed模块深度美化Android
热门文章
- http协议的状态码
- 《代码阅读方法与实践》阅读笔记一
- C++中可以以“类名::成员函数”直接引用成员函数哦!
- leetcode算法题--最大加号标志★
- 获得目录下文件数和文件行数
- Sql Server实用操作-动态sql语句基本语法
- 使用ionic cordova build android --release --prod命令打包报错解决方法
- Visual Studio 2015编译Lua 5.3.4遇到的坑
- Log4j扩展使用--自定义输出
- IO流(文本文件读取练习)