电子日历记事本--Java课程设计(4)

2019-06-11 16:26

明年=new JButton(\下年\ 去年=new JButton(\上年\

add(去年); //添加按钮到窗体 add(showYear); add(明年);

showYear.addActionListener(this); //注册监听器 去年.addActionListener(this); 明年.addActionListener(this); }

public void setYear(int year) {

this.year=year;

showYear.setText(\ //设置文本框内容为year的值 }

public int getYear() {

return year; }

public void actionPerformed(ActionEvent e) {

if(e.getSource()==去年) {

year=year-1;

showYear.setText(\ 日历.setYear(year);

日历.设置日历牌(year,日历.getMonth()); }

else if(e.getSource()==明年) {

year=year+1;

showYear.setText(\ 日历.setYear(year);

日历.设置日历牌(year,日历.getMonth()); }

else if(e.getSource()==showYear) {

try { year=Integer.parseInt(showYear.getText()); showYear.setText(\ 日历.setYear(year); 日历.设置日历牌(year,日历.getMonth());

12

} catch(NumberFormatException ee) { showYear.setText(\ 日历.setYear(year); 日历.设置日历牌(year,日历.getMonth()); } } } }

class Month extends Box implements ActionListener { int month; JTextField showMonth=null; JButton 下月,上月; CalendarPad 日历; public Month(CalendarPad 日历) { super(BoxLayout.X_AXIS); this.日历=日历; showMonth=new JTextField(2); month=日历.getMonth(); showMonth.setEditable(false); showMonth.setForeground(Color.blue); showMonth.setFont(new Font(\ 下月=new JButton(\下月\ 上月=new JButton(\上月\ add(上月); add(showMonth); add(下月); 上月.addActionListener(this); 下月.addActionListener(this); showMonth.setText(\ } public void setMonth(int month) { if(month<=12&&month>=1) { this.month=month; } else

13

{

this.month=1; }

showMonth.setText(\}

public int getMonth() {

return month; }

public void actionPerformed(ActionEvent e) {

if(e.getSource()==上月) {

if(month>=2) { month=month-1; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); }

else if(month==1) { month=12; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); }

showMonth.setText(\ }

else if(e.getSource()==下月) {

if(month<12) { month=month+1; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); }

else if(month==12) { month=1; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); }

showMonth.setText(\ }

14

} }

class NotePad extends JPanel implements ActionListener { JTextArea text; JButton 保存日志,删除日志; Hashtable table; JLabel 信息条; int year,month,day; File file; CalendarPad calendar; public NotePad(CalendarPad calendar) { this.calendar=calendar; year=calendar.getYear(); month=calendar.getMonth(); day=calendar.getDay(); table=calendar.getHashtable(); file=calendar.getFile(); 信息条=new JLabel(\年\月\日\ 信息条.setFont(new Font(\ 信息条.setForeground(Color.blue); text=new JTextArea(10,10); 保存日志=new JButton(\保存日志\ 删除日志=new JButton(\删除日志\ 保存日志.addActionListener(this); 删除日志.addActionListener(this); setLayout(new BorderLayout()); JPanel pSouth=new JPanel(); add(信息条,BorderLayout.NORTH); pSouth.add(保存日志); pSouth.add(删除日志); add(pSouth,BorderLayout.SOUTH); add(new JScrollPane(text),BorderLayout.CENTER); } public void actionPerformed(ActionEvent e) { if(e.getSource()==保存日志) { 保存日志(year,month,day);

15

}

else if(e.getSource()==删除日志) {

删除日志(year,month,day); } }

public void setYear(int year) {

this.year=year; }

public int getYear() {

return year; }

public void setMonth(int month) {

this.month=month; }

public int getMonth() {

return month; }

public void setDay(int day) {

this.day=day; }

public int getDay() {

return day; }

public void 设置信息条(int year,int month,int day) {

信息条.setText(\年\月\日\}

public void 设置文本区(String s) {

16


电子日历记事本--Java课程设计(4).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:2019年高考理科数学仿真冲刺卷及答案(一)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: