日历记事本

 
  
日历记事本就是一个日历再加上记事的功能。你可以把将来要做的事情都记在记事本上,等到了那天就会显示出来,你也可以看见你以前做的事情(当然是指纪录在记事本上的)。请各位多多指教! 
import java.awt.*; 
import java.awt.event.*; 
import javax.swing.*; 
import java.util.*; 
import java.text.*; 
import java.io.*; 
public class Note extends Frame { 


private MenuBar mb; 
private Menu mset_param ,mhelp; 
private MenuItem mibc ,miSound; 
private MenuItem miabout; 
//缺省的背景颜色 
private static Color backgroundcolor = Color.GRAY; 


//funtction of the button on plcb is chose year andmonth 
//and set alarm colock and remind booking 
private JCheckBox remindBook ,alarmColock; 
private JComboBox cbyears ,cbmonths; 
private JPanel plcb; 
//日历按钮 
private JPanel plbt; 
private JButton button[]; 
//add vector to contain button[],so that find it 
private Vector v; 
//save the year and month 
private String choseyear ,chosemonth; 
private int choseyearint ,chosemonthint; 
private boolean changed = false; 
private boolean fileExist = false;//the application first run to find file 
private static boolean needSound; 


//add text to write down what to do in the future 
private TextArea tanote; 
private JPanel plta; 


//默认的年份 
private final static String years[]={ 
"1995" ,"1996" ,"1997" ,"1998" ,"1999" ,"2000" , 
"2001" ,"2002" ,"2003" ,"2004" ,"2005" ,"2006" , 
"2007" ,"2008" ,"2009" ,"2010" ,"2011" ,"2012" , 
"2013" ,"2014" ,"2015" ,"2016" ,"2017" ,"2018" , 
"2019" ,"2020" 
}; 


private static final String months[] = { 
"January" ,"February" ,"March" ,"April" ,"May" ,"June" ,"July" ,"August" , 
"September" ,"October" ,"November" ,"December" 
}; 


private final static int dom[] = { 
31 ,28 ,31 ,30 ,31 ,30 ,31 ,31 ,30 ,31 ,30 ,31 
}; 


//save the first day of the month to use 
private int start; 
//save the button who is entered 
private int btnIndex; 


public Note() { 
mb = new MenuBar(); 
mset_param = new Menu("设置"); 
mhelp = new Menu("帮助"); 
mibc = new MenuItem("背景"); 
miSound = new MenuItem("声音"); 
miabout = new MenuItem("关于..."); 


mset_param.add(mibc); 
mset_param.addSeparator(); 
mset_param.add(miSound); 
mhelp.add(miabout); 
setMenuBar(mb); 
mb.add(mset_param); 
mb.setHelpMenu(mhelp); 


MListener ml = new MListener(); 
mibc.addActionListener(ml); 
miabout.addActionListener(ml); 
miSound.addActionListener(ml); 


cbyears = new JComboBox(); 
cbmonths = new JComboBox(); 
plcb = new JPanel(); 
plcb.setLayout(new FlowLayout()); 
JLabel lyears = new JLabel("年份:"); 
JLabel lmonths = new JLabel("月份:"); 
plcb.add(lyears); 
plcb.add(cbyears); 
plcb.add(lmonths); 
plcb.add(cbmonths); 
remindBook = new JCheckBox("预约提示",true); 
alarmColock = new JCheckBox("闹钟"); 
// Dimension d = new Dimension(); 
// remindBook.setSize(d); 
// remindBook.getSize(d); 
// System.out.println("W:"+d.getWidth()+" H:"+d.getHeight()); 
plcb.add(remindBook); 
plcb.add(alarmColock); 
remindBook.addActionListener(new RemindListener()); 
alarmColock.addActionListener(new RemindListener()); 
add(plcb ,BorderLayout.NORTH); 


//add calendar 
getCalendar(); 


plbt = new JPanel(); 
plbt.setBackground(Color.BLUE); 
plbt.setLayout(new GridLayout(7 ,7)); 


plbt.add(new JLabel(" 星期日")); 
plbt.add(new JLabel(" 星期一")); 
plbt.add(new JLabel(" 星期二")); 
plbt.add(new JLabel(" 星期三")); 
plbt.add(new JLabel(" 星期四")); 
plbt.add(new JLabel(" 星期五")); 
plbt.add(new JLabel(" 星期六")); 


//add calendar button to frame 
//add button to vector; 
v = new Vector(); 
button = new JButton[42]; 
for(int i=0;i<41;i++){ 
button[i] = new JButton(); 
plbt.add(button[i]); 
button[i].addActionListener(new ButtonListener()); 
v.add(button[i]); 



button[41] = new JButton(); 
plbt.add(button[41]); 
button[41].setText("保存"); 
button[41].addActionListener(new SaveListener()); 
add(plbt ,BorderLayout.CENTER); 


//add note book 
// plta = new JPanel(); 
tanote = new TextArea(5 ,80); 
// tanote.addTextListener(new tanoteTextListener()); 
// tanote.setColumns(80); 
// plta.add(tanote); 
// tanote.SCROLLBARS_VERTICAL_ONLY; 
add(tanote ,BorderLayout.SOUTH); 


/* 
//add date to button 
GregorianCalendar calendar = new GregorianCalendar(choseyearint ,chosemonthint ,1); 
int start = calendar.get(Calendar.DAY_OF_WEEK)-1; 
int daysInMonth = dom[chosemonthint]; 
if(calendar.isLeapYear(choseyearint)&&chosemonthint == 1){ 
++daysInMonth; 

for(int i =0;i<daysInMonth;i++){ 
button[start+i].setText(" "+(i+1)+" "); 

*/ 
//add the default year and month to JComboBox 
for(int i= 0;i<=25;i++){ 
cbyears.addItem(years[i]); 

for(int i=0;i<12;i++){ 
cbmonths.addItem(months[i]); 

/* 
//add current year and month 
cbyears.setSelectedIndex(choseyearint-1995); 
cbmonths.setSelectedIndex(chosemonthint); 
*/ 


//show date to calendar 
showDate(); 
//open file add to note 
Calendar now = new GregorianCalendar(); 
int num = start + now.get(Calendar.DAY_OF_MONTH)-1; 
btnIndex = num; 
readFile(num); 
fileSound(); 


//add threadcb to listen jcombobox state 
new ThreadCB().start(); 


//listen the JComboBox of years and months 
cbyears.addItemListener(new cbyearsItemListener()); 
cbmonths.addItemListener(new cbmonthsItemListener()); 


addWindowListener(new WindowAdapter() { 
public void windowClosing(WindowEvent e) { 
dispose(); 
System.exit(0); 

}); 



/** 
*add menu listener to know the menu what do want to do 
*/ 
class MListener implements ActionListener{ 
public void actionPerformed(ActionEvent e){ 
MenuItem i = (MenuItem)e.getSource(); 
if(i.equals(miabout)){ 
JOptionPane.showMessageDialog(null ,"日历记事本程序V1.0","关于..." ,JOptionPane.INFORMATION_MESSAGE); 

else if(i.equals(mibc)){ 
//backgroundcolor = Color.BLACK; 
backgroundcolor = JColorChooser.showDialog(null ,"选择颜色..." ,getBackground()); 
setBackground(backgroundcolor); 
plbt.setBackground(backgroundcolor); 
// System.out.println(choseyear); 
 

else{ 
JOptionPane.showMessageDialog(null ,"I am sorry ,this function is not complation" ,"Sorry" ,JOptionPane.INFORMATION_MESSAGE); 





/** 
*add the year JComboBox listener to know what active 
*/ 
class cbyearsItemListener implements ItemListener{ 
public void itemStateChanged(ItemEvent e){ 
// System.out.println(e.paramString()); 
// System.out.println(e.getStateChange()); 
// System.out.println(e.getItem().toString()); 
// if(e.getSource().equals("1997")){ 
// System.out.println("1997 is chosed"); 
// } 
// else{ 
// System.out.println("the System is not chose 1997"); 
// } 
// choseyear = e.getItem().toString(); 
changed = true; 
// showDate(); 
// cbmonths.setSelectedIndex(5); 




/** 
*add the month JComboBox listener to know what active 
*/ 
class cbmonthsItemListener implements ItemListener{ 
public void itemStateChanged(ItemEvent e){ 
// System.out.println(choseyear); 
// chosemonth = e.getItem().toString(); 
changed = true; 


// chosemonthint = Integer.parseInt(chosemonth); 
// System.out.println(chosemonthint); 
// showDate(); 




public static void main(String args[]) { 
System.out.println("Starting Note..."); 
Note mainFrame = new Note(); 
mainFrame.setSize(600, 400); 
mainFrame.setTitle("日历记事本"); 
mainFrame.setBackground(backgroundcolor); 
mainFrame.setVisible(true); 
for(int i=0;i<10;i++){ 
System.out.print("\007"); 

// Thread dd = new ThreadCB(); 
// dd.start(); 
// mainFrame.paintCalendar(); 



protected void getCalendar(){ 
Calendar now = new GregorianCalendar(); 
// System.out.println("year :"+now.get(Calendar.YEAR)); 
// System.out.println("month:"+now.get(Calendar.MONTH)); 
// int y = now.get(Calendar.YEAR); 
// choseyear = Integer.toString(y); 
// int m = now.get(Calendar.MONTH); 
// chosemonth = Integer.toString(m+1); 
choseyearint = now.get(Calendar.YEAR); 
chosemonthint = now.get(Calendar.MONTH); 
// System.out.println("y "+choseyear+"::"+chosemonth); 



/** 
*show date to calendar 
*/ 
protected void showDate(){ 
GregorianCalendar calendar = new GregorianCalendar(choseyearint ,chosemonthint ,1); 
start = calendar.get(Calendar.DAY_OF_WEEK)-1; 
int daysInMonth = dom[chosemonthint]; 
if(calendar.isLeapYear(choseyearint)&&chosemonthint == 1){ 
++daysInMonth; 

for(int i =0;i<daysInMonth;i++){ 
button[start+i].setForeground(Color.BLACK); 
button[start+i].setText(" "+(i+1)+" "); 

//set current day 
int nowDay = start + calendar.get(Calendar.DAY_OF_MONTH); 
button[nowDay+1].setForeground(Color.RED); 
//add current year and month 
cbyears.setSelectedIndex(choseyearint-1995); 
cbmonths.setSelectedIndex(chosemonthint); 



//listen the buttons active 
class ButtonListener implements ActionListener{ 
public void actionPerformed(ActionEvent e){ 
Object obj = e.getSource(); 
// System.out.println("haha"+e.getSource()); 
btnIndex = v.indexOf(obj); 
readFile(btnIndex); 
/* switch(v.indexOf(obj)){ 
case 1: 
System.out.println("i am button1"); 
break; 
case 2: 
// System.out.println("I am button2"); 
readFile(2); 
break; 
case 41: 
System.out.println(tanote.getText()); 
break; 
default: 
System.out.println("I do not know who am I"); 
break; 

*/ } 



/** 
*create a thread to listen the year or month′s state 
*/ 
class ThreadCB extends Thread{ 
public void run(){ 
while(true){ 
if(changed){ 
changed = false; 
choseyearint = cbyears.getSelectedIndex()+1995; 
chosemonthint = cbmonths.getSelectedIndex(); 
//System.out.println("y:"+choseyearint+":M:"+chosemonthint); 
for(int i=0;i<40;i++){ 
button[i].setText(""); 

showDate(); 

try{ 
sleep(200); 

catch(InterruptedException e){ 
System.err.println(e); 






/** 
* add note book listener to know the textarea active 
*/ 
/* 
class tanoteTextListener implements TextListener{ 
public void textValueChanged(TextEvent e){ 
//System.out.println(e.getSource()); 

}*/ 


/** 
*check file to know the file is exist 
* if exist,read it to the note book 
*/ 
protected void readFile(int bt){ 
int y = cbyears.getSelectedIndex()+1995;//real year 
int m = cbmonths.getSelectedIndex()+1;//real month 
String fileName = Integer.toString(y) + Integer.toString(m)+"button"+Integer.toString(bt); 
// System.out.println("I am dudu"); 
// System.out.println(fileName); 
// String fileName = "testDay.java"; 


File file = new File(fileName); 
BufferedReader is; 
String line; 
StringBuffer sb = new StringBuffer(); 


tanote.setText(""); 
if(file.exists()){ 
try{ 
is = new BufferedReader(new FileReader(fileName)); 


while((line = is.readLine())!= null){ 
sb.append(line); 
sb.append("\n"); 

is.close(); 

catch(IOException e){ 
System.err.println(e); 
System.exit(0); 

tanote.setText(sb.toString()); 
fileExist = true; 

else{ 
System.out.println(fileName+" is not exists"); 






/** 
*sound 
*/ 
protected void fileSound(){ 
if(remindBook.isSelected()){ 
if(fileExist){ 
/* for(int i=0;i<10;i++){ 
System.out.println("\007"); 

*/ 
needSound = true; 





/** 
*listen the save button active 
*/ 
class SaveListener implements ActionListener{ 
public void actionPerformed(ActionEvent e){ 
int bt = btnIndex; 
int y = cbyears.getSelectedIndex()+1995;//real year 
int m = cbmonths.getSelectedIndex()+1;//real month 
String fileName = Integer.toString(y) + Integer.toString(m)+"button"+Integer.toString(bt); 


try{ 
BufferedWriter bw = new BufferedWriter(new FileWriter(fileName)); 
//int row = tanote.getRows(); 
//System.out.println("rows:"+row); 
String s = tanote.getText(); 
System.out.println("length:"+s.length()); 
bw.write(s); 


bw.close(); 

catch(IOException ev){ 
System.err.println(ev); 
System.exit(0); 





// 
class RemindListener implements ActionListener{ 
public void actionPerformed(ActionEvent ae){ 
Object obj = ae.getSource(); 
if(obj.equals(remindBook)){ 
if(remindBook.isSelected()){ 
System.out.println("I am selected"); 

else{ 
System.out.println("I am not selected"); 


else{ 
if(alarmColock.isSelected()){ 
// System.out.println("I am selected"); 
final JFrame jf = new JFrame("设置时间"); 
jf.setSize(300,100); 
jf.setLocation(200 ,200); 
jf.setVisible(true); 
// Font f = new Font( ,Font.BOLD ,20); 
JLabel jl = new JLabel("逗你玩"); 
String name=jl.getFont().getName(); 
// System.out.println("Font:"+name);//name′s value is Dialog 
Font f = new Font(name ,Font.BOLD+Font.ITALIC ,20); 
jl.setForeground(Color.red); 
jl.setFont(f); 
jf.getContentPane().setLayout(new GridLayout(5 ,2)); 
jf.getContentPane().add(new JLabel(" ")); 
jf.getContentPane().add(jl); 
jf.getContentPane().add(new JLabel("sorry! this function is not do!!")); 
jf.pack(); 
jf.addWindowListener(new WindowAdapter(){ 
public void windowClosing(WindowEvent we){ 
jf.dispose(); 

}); 

else{ 
System.out.println("I am not selected"); 




}
 
计算机科学与技术本科专业 Java课程设计任务书 题目: 日历记事本 学生姓名: 学号: 班级: 题目类型:软件工程(R) 指导教师: 一. 题目简介 该设计要求设计一个带有日程提醒功能的日历。 通过该题目的设计,培养学生面向对象程序设计的思想,要求学生达到熟练掌握Java语言的基本知识和技能,基本掌握面向对象程序设计的基本思路和方法,能够利用所学的基本知识和技能,解决简单的面向对象程序设计问题。同时强调好的程序设计风格,提高解决实际问题的能力。 二. 主要任务 1、查阅文献资料,一般在5篇以上; 2、应用系统分析,建立该系统的功能模块框图以及界面的组织和设计; 3、分析系统中的各个实体及它们之间的关系包括属性和方法; 4、根据问题描述,设计系统的类层次; 5、完成类层次中各个类的描述(包括属性和方法); 6、完成类中各个成员函数的定义; 7、完成系统的应用模块; 8、完成系统的软件开发和测试工作; 9、撰写设计说明书; 10、做好答辩工作。 三. 主要内容、功能及技术指标 (一) 基本要求: 编写一个Applet小应用程序能够显示时间,当用户最小化Applet时,程序会 被挂起,当还原Applet时,程序又会恢复执行,同时Applet中应显示挂起和恢复的时间。 (二)系统要求: 1、要求利用面向对象的方法以及Java的编程思想来完成系统的设计; 2、要求在设计的过程中,建立清晰的类层次; 3、在系统设计中要分析和定义各个类,每个类中要有各自的属性和方法; 4、在系统的设计中,要求运用面向对象的机制(继承、派生及多态性)来实现系统功能。 5、该系统的要求: (1)显示信息:用户可以向前翻页查询前一个月的日期,也可以向后翻页查询下一个月的日期。 (2)定时提醒:用户可以针对某一天来添加,删除和编辑这一天的日程提醒信息,当系统时间和提醒时间相吻合时,给出具有提示信息的对话框; (3)查询信息:用户可以查询到某个月的所有提示信息。 四. 提交的成果 1. 设计说明书一份,内容包括: 1) 中文摘要100字;关键词3-5个; 2) 序言; 3) 基本要求实现(包括程序流程图;部分代码;) 4) 系统要求实现 系统分析与设计(包括设计系统的类层次,各个实体及它们之间的关系) 详细设计(包括各个类的详细设计,如数据成员及成员函数的设计); 系统测试(包含测试方案、测试用例、测试结果及软件可靠性分析); 软件使用说明书(核心界面说明); 5)设计总结、参考文献、致谢等。 五. 主要参考文献 [1]曲朝阳,杨杰明等.Java程序设计. 北京: 清华大学出版社,2008.10 [2]耿祥以,张跃平.Java大学生实用教程. 北京: 电子工业出版社,2012.6 [3]明日科技.Java经典编程.北京:清华大学出版社,2012.10 [4]李尊朝,苏军.Java语言程序设计.北京:中国铁道出版社,2004.2 [5]王博. 面向对象的建模、设计技术与方法. 北京希望电脑公司,1990. 六. 各阶段时间安排(共2周): 周次 日期 内容 地点 第1周 星期一 教师讲解设计要求,准备参考资料 教室 星期二 分析系统,方案设计 实验室 星期三~五 编程 实验室 第2周 星期一~三 编程、调试程序 实验室 星期四 写设计书 实验室 星期五 答辩 实验室
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值