java中编写日历的代码 java编程日历( 四 )


north.add(showYear);
north.add(nextYear);
north.add(previousMonth);
north.add(showMonth);
north.add(nextMonth);
add(north,BorderLayout.NORTH);
saveDailyRecord=new JButton("保存日志") ;
deleteDailyRecord=new JButton("删除日志");
readDailyRecord=new JButton("读取日志");
saveDailyRecord.addActionListener(this);
deleteDailyRecord.addActionListener(this);
readDailyRecord.addActionListener(this);
JPanel pSouth=new JPanel();
pSouth.add(saveDailyRecord);
pSouth.add(deleteDailyRecord);
pSouth.add(readDailyRecord);
add(pSouth,BorderLayout.SOUTH);
setVisible(true);//根据参数 b 的值显示或隐藏此 Window
setBounds(60,60,660,480);
validate();//验证此容器及其所有子组件
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //设置用户在此窗体上发起 "close" 时默认执行的操作
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==nextYear){
year++;
showYear.setText(""+year);
calendarMessage.setYear(year);
calendarPad.setCalendarMessage(calendarMessage);
calendarPad.showMonthCalendar();
notePad.setShowMessage(year,month,day);
doMark();
}
else if(e.getSource()==previousYear){
year--;
showYear.setText(""+year);
calendarMessage.setYear(year);
calendarPad.setCalendarMessage(calendarMessage);
calendarPad.showMonthCalendar();
notePad.setShowMessage(year,month,day);
doMark();
}
else if(e.getSource()==nextMonth){
month++;
if(month12) month=1;
showMonth.setText(" "+month);
calendarMessage.setMonth(month);
calendarPad.setCalendarMessage(calendarMessage);
calendarPad.showMonthCalendar();
notePad.setShowMessage(year,month,day);
doMark();
}
else if(e.getSource()==previousMonth){
month--;
if(month1) month=12;
showMonth.setText(" "+month);
calendarMessage.setMonth(month);
calendarPad.setCalendarMessage(calendarMessage);
calendarPad.showMonthCalendar();
notePad.setShowMessage(year,month,day);
doMark();
}
else if(e.getSource()==showYear){
String s=showYear.getText().trim();
char a[]=s.toCharArray();
boolean boo=false;
for(int i=0;ia.length;i++)
if(!(Character.isDigit(a[i])))
boo=true;
if(boo==true)//弹出“警告”消息对话框
JOptionPane.showMessageDialog(this,"您输入了非法年份","警告", JOptionPane.WARNING_MESSAGE);
else if(boo==false)
year=Integer.parseInt(s);
showYear.setText(""+year);
calendarMessage.setYear(year);
calendarPad.setCalendarMessage(calendarMessage);
calendarPad.showMonthCalendar();
notePad.setShowMessage(year,month,day);
doMark();
}
else if(e.getSource()==saveDailyRecord){
notePad.save(dir,year,month,day);
doMark();
}
else if(e.getSource()==deleteDailyRecord){
notePad.delete(dir,year,month,day);
doMark();
}
else if(e.getSource()==readDailyRecord)
notePad.read(dir,year,month,day);
}
public void mousePressed(MouseEvent e){
JTextField text=(JTextField)e.getSource();
String str=text.getText().trim();
try{ day=Integer.parseInt(str);
}
catch(NumberFormatException exp){
}
calendarMessage.setDay(day);
notePad.setShowMessage(year,month,day);
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e){}
public void mouseExited(MouseEvent e) {}
public void mouseClicked(MouseEvent e) {}
public void focusGained(FocusEvent e){
Component com=(Component)e.getSource();
com.setBackground(Color.red);
}
public void focusLost(FocusEvent e){
Component com=(Component)e.getSource();
com.setBackground(backColor);

推荐阅读