import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.SimpleDateFormat;
import java.util.*;
public class MyCalendar extends JFrame implements ActionListener{
Map<Integer,Note> noteMap=new HashMap<>();
//面板容器
private final JPanel YearMonthJpl = new JPanel();
private final JPanel WeekJpl = new JPanel();
private final JPanel DateJpl = new JPanel();
//年份滑动选择
private final JSpinner YearSpinner = new JSpinner();
//月份下拉选择
private final JComboBox<Integer> MonthComBox = new JComboBox<>();
//年月的标签
private final JLabel YearLbl = new JLabel("Year");
private final JLabel MonthLbl = new JLabel("Month");
private final JLabel currentLbl =new JLabel();
private final JMenuBar menuBar=new JMenuBar();
private final JMenu SearchMenu=new JMenu("Search");
private final JMenu CountMenu=new JMenu("Count For This Month");
private final JMenu CheckMenu=new JMenu("Check");
private final JMenuItem check_time=new JMenuItem("check time");
private final JMenuItem search_by_id_item=new JMenuItem("search by id");
private final JMenuItem search_by_keys_item=new JMenuItem("search by keys");
private final JMenuItem count_by_type_item=new JMenuItem("count by type");
private final JMenuItem count_by_keys_item=new JMenuItem("count by keys");
private final JPanel searchJpl=new JPanel();
private final JTextField searchTf=new JTextField(20);
JDialog noteDialog=new JDialog(this,"note",false);
JPanel noteJpl=new JPanel();
public void init(){
YearSpinner.setPreferredSize(new Dimension(50,30));
MonthComBox.setPreferredSize(new Dimension(50,30));
YearSpinner.setToolTipText("input year");
MonthComBox.setToolTipText("select month");
searchTf.setToolTipText("input sth and click the menu to search");
searchJpl.setBounds(12,0,7*Const.SIZE,Const.SIZE);
YearMonthJpl.setBounds(12,Const.SIZE,7*Const.SIZE,Const.SIZE);
WeekJpl.setBounds(12,2*Const.SIZE,7*Const.SIZE,Const.SIZE);
DateJpl.setLocation(12,3*Const.SIZE);
YearMonthJpl.add(YearSpinner);
YearMonthJpl.add(YearLbl);
YearMonthJpl.add(MonthComBox);
YearMonthJpl.add(MonthLbl);
Box searchBox = Box.createVerticalBox();
searchBox.add(searchTf);
searchBox.add(currentLbl);
searchJpl.add(searchBox);
Calendar currentCalendar=Calendar.getInstance();
currentLbl.setText("Date Now "+currentCalendar.get(Calendar.YEAR)+"."+(currentCalendar.get(Calendar.MONTH)+1)+"."+currentCalendar.get(Calendar.DATE));
this.add(YearMonthJpl);
this.add(WeekJpl);
this.add(DateJpl);
this.add(searchJpl);
this.addYear();
this.addMonth();
this.addWeeks();
this.addDays();
this.setJMenuBar(menuBar);
menuBar.add(SearchMenu);
menuBar.add(CountMenu);
menuBar.add(CheckMenu);
SearchMenu.add(search_by_id_item);
SearchMenu.add(search_by_keys_item);
CountMenu.add(count_by_keys_item);
CountMenu.add(count_by_type_item);
CheckMenu.add(check_time);
search_by_id_item.addActionListener(e -> {
int id=Integer.parseInt(searchTf.getText());
noteJpl.removeAll();
noteJpl.repaint();
createNoteDialog(id);
});
search_by_keys_item.addActionListener(e -> {
noteJpl.removeAll();
noteJpl.repaint();
String key=searchTf.getText();
for(Map.Entry<Integer,Note> entry : noteMap.entrySet()){
String[] keys=entry.getValue().keys;
for(String i :keys) {
if ((i==null))
continue;
if(i.equals(key)){
createNoteDialog(entry.getKey());
}
}
}
});
count_by_type_item.addActionListener(e -> {
Calendar calendar = Calendar.getInstance();
int year=getSelectedYear();
int month=getSelectedMonth();
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month-1);
calendar.set(Calendar.DATE,1);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
Map<Integer,Integer> typeMap=new HashMap<>();
for (int i = 1; i <= days; i++) {
int id=Integer.parseInt(year+""+month+""+i);
Note note=noteMap.get(id);
if(note==null)
continue;
if(!typeMap.containsKey(note.getType()))
typeMap.put(note.getType(),note.getCost());
else
typeMap.put(note.getType(),typeMap.get(note.getType())+note.getCost());
}
JDialog countDialog = new JDialog(this,"count by type");
JTextArea countTa= new JTextArea("Count For This Month:\n",10,10);
countTa.setEditable(false);
for(Map.Entry<Integer,Integer> entry :typeMap.entrySet())
countTa.setText(countTa.getText()+ Const.TYPE_NAME[entry.getKey()]+": "+entry.getValue()+"\n");
if(typeMap.isEmpty())
countTa.setText(countTa.getText()+"None");
countDialog.add(countTa,BorderLayout.CENTER);
countDialog.setBounds(Const.FRAME_X,Const.FRAME_Y,6*Const.SIZE,6*Const.SIZE);
countDialog.setVisible(true);
});
count_by_keys_item.addActionListener(e->{
Calendar calendar = Calendar.getInstance();
int year=getSelectedYear();
int month=getSelectedMonth();
calendar.set(Calendar.YEAR,year);
calendar.set(Calendar.MONTH,month-1);
calendar.set(Calendar.DATE,1);
int days = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
Map<String,Integer> keysMap=new HashMap<>();
for (int i = 1; i <= days; i++) {
int id=Integer.parseInt(year+""+month+""+i);
Note note=noteMap.get(id);
if(note==null)
continue;
for(String key : note.keys){
if(key==null)
continue;
if(!keysMap.containsKey(key))
keysMap.put(key,note.getCost());
else
keysMap.put(key,keysMap.get(key)+note.getCost());
}
}
JDialog countDialog = new JDialog(this,"count by keys");
JTextArea countTa= new JTextArea("Count For This Month:\n",10,10);
countTa.setEditable(false);
for(Map.Entry<String,Integer> entry :keysMap.entrySet())
countTa.setText(countTa.getText()+ entry.getKey()+": "+entry.getValue()+"\n");
if(keysMap.isEmpty())
countTa.setText(countTa.getText()+"None");
countDialog.add(countTa,BorderLayout.CENTER);
countDialog.setBounds(Const.FRAME_X,Const.FRAME_Y,6*Const.SIZE,6*Const.SIZE);
countDialog.setVisible(true);
});
check_time.addActionListener(e -> {
SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss ");
Date date = new Date(System.currentTimeMillis());
JOptionPane.showMessageDialog(this,"Time Now: "+formatter.format(date));
});
this.setTitle("Calendar");
this.setBounds(Const.FRAME_X,Const.FRAME_Y,Const.FRAME_WIDTH,Const.FRAME_HEIGHT+Const.SIZE);
/
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
题目:具有每日记账功能的简易日历程序 要求:编写具有图形用户界面(GUI)的日历组件显示日期和时间并进行适当的功能扩充。 主要功能: 1、显示当月日历,当前日期、当前时间; 2、可查询任意月以及任意年的日历; 3、正常运行和退出程序。 4、每日具有记账功能,需要至少包含1)记账id;2)记账类型;2)支出费用;3)关键字(关键字写为一行,关键字数量不限,使用分号分割<需查阅使用>) 5、能够通过关键字查询某一种类型的记账记录。 6、对当月记账类型的汇总;对特定关键字的记账汇总。 除Swing/AWT以外,可能是用到的类:日期类;String/StringBuffer;容器类;Math类,IO相关类。
资源详情
资源评论
资源推荐
收起资源包目录
MyCalendar.zip (55个子文件)
MyCalendar
.git
index 1KB
hooks
fsmonitor-watchman.sample 5KB
pre-push.sample 1KB
prepare-commit-msg.sample 1KB
pre-merge-commit.sample 416B
applypatch-msg.sample 478B
pre-commit.sample 2KB
pre-receive.sample 544B
pre-applypatch.sample 424B
commit-msg.sample 896B
pre-rebase.sample 5KB
update.sample 4KB
post-update.sample 189B
push-to-checkout.sample 3KB
config 247B
description 73B
refs
tags
heads
master 41B
remotes
origin
master 41B
logs
refs
heads
master 164B
remotes
origin
master 148B
HEAD 164B
objects
65
de034bf818cd3ec2837c67e288289659ed3b67 353B
90
fffdcd9aa821c6f68cc9c6980766b45564e4d7 122B
87
6a1499c09dc083612f43c53c0ae71b9c30c5b1 69B
2d
fbcab5b37204dff4d2f33e14f492d350d81fbd 8KB
69
9715802595f0a67e97848887a0d40e33dbbd3c 211B
9f
66d0e3c0921520c11c1f5507a8b171a5617dca 53B
61
420d905bf70efae5184406d413808beb192360 119B
b2
13c31fe3d94cf5aba6f9800323fdf0b81a8c58 52B
info
c4
699ad91735536ede483eeac744fc4a960cec9f 312B
6e
6a7a2709bcfa8f0d8881df531e7feae9272f51 4KB
pack
fe
85bbbaeb7a33914941a30bcbbfc7fa31e024ec 119B
8b
187b13fd3a2028e7481dc6ce40703a92ae5051 184B
e5
8dad6da751924696461438a97545fe16c26133 132B
b1
75004dbd2b8213701c57d2757b6b522ff807af 184B
26
d33521af10bcc7fd8cea344038eaaeb78d0ef5 63B
c2
b5fd4343653ea21b9d3feabed5a117eec90cfa 737B
f5
09279e80c4e2f2de71917889f78bb316e047f4 474B
c9
0834f2d607afe55e6104d8aa2cdfffb713f688 263B
info
exclude 240B
COMMIT_EDITMSG 631B
HEAD 23B
src
MyCalendar.java 14KB
Note.java 746B
Const.java 747B
.idea
misc.xml 277B
vcs.xml 185B
modules.xml 267B
workspace.xml 3KB
.gitignore 50B
MyCalendar.code-workspace 60B
out
production
MyCalendar
Const.class 1KB
MyCalendar.class 15KB
Note.class 832B
MyCalendar.iml 433B
共 55 条
- 1
ColdFramer
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 科目一,扣分法规的的的的
- 科目一易错题,整理的的的的
- C#ASP.NET企业智能办公OA系统源码带文档数据库 SQL2008源码类型 WebForm
- mixiao网站下载的模型 替换ue 小白人
- YOLOv11实现并使用NVIDIA TensorRT进行优化的对象检测项目源码
- python爬虫实战开发之bs4应用和xpath结合实战操作.zip
- 电子课程设计项目《多功能数字时钟(包括了基本的计数显示,还有提高部分,如星期和月份的动态展示)》+项目源码+文档说明
- C#大型OA源码 网络在线办公平台源码数据库 SQL2008源码类型 WebForm
- RV1106编译速度、驱动加载
- tensorflow安装-不同操作系统环境下TensorFlow的安装指南与步骤
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5