5
import javax.swing.*; import java.awt.*;
import java.awt.event.*;
public class Month extends Box implements ActionListener//ActionListener接口 {
int month;
JTextField showMonth=null; JButton RMonth,NMonth; CalendarPad cal;
public Month(CalendarPad c) {
super(BoxLayout.X_AXIS); this.cal=c;
showMonth=new JTextField(2); month=c.getMonth();
showMonth.setEditable(false);
showMonth.setForeground(Color.blue); showMonth.setFont(new Font(\NMonth=new JButton(\下月\RMonth=new JButton(\上月\ add(RMonth); add(showMonth); add(NMonth);
RMonth.addActionListener(this); NMonth.addActionListener(this); showMonth.setText(\ }
public void setMonth(int month) {
if(month<=12&&month>=1) {
this.month=month; } else {
this.month=1; }
showMonth.setText(\ }
public int getMonth() {
return month; }
6
public void actionPerformed(ActionEvent e) {
if(e.getSource()==RMonth) {
if(month>=2) {
month=month-1; cal.setMonth(month);
cal.setCal(cal.getYear(),month); }
else if(month==1) {
month=12;
cal.setMonth(month);
cal.setCal(cal.getYear(),month); }
showMonth.setText(\ }
else if(e.getSource()==NMonth) {
if(month<12) {
month=month+1; cal.setMonth(month);
cal.setCal(cal.getYear(),month); }
else if(month==12) {
month=1;
cal.setMonth(month);
cal.setCal(cal.getYear(),month); }
showMonth.setText(\ } } }
//对年分的选择
package javaapplication13;
import javax.swing.*; import java.awt.*;
import java.awt.event.*;
public class Year extends Box implements ActionListener//ActionListener接口
7
{
int year;
JTextField showYear=null; JButton NYear,RYear; CalendarPad cal;
public Year(CalendarPad c) {
super(BoxLayout.X_AXIS); showYear=new JTextField(4); showYear.setForeground(Color.blue); showYear.setFont(new Font(\ this.cal=c;
year=cal.getYear();
NYear=new JButton(\下年\RYear=new JButton(\上年\ add(RYear); add(showYear); add(NYear);
showYear.addActionListener(this); RYear.addActionListener(this); NYear.addActionListener(this); }
public void setYear(int year) {
this.year=year;
showYear.setText(\ }
public int getYear() {
return year; }
public void actionPerformed(ActionEvent e) {
if(e.getSource()==RYear) {
year=year-1;
showYear.setText(\ cal.setYear(year);
cal.setCal(year,cal.getMonth()); }
else if(e.getSource()==NYear) {
year=year+1;
showYear.setText(\
8
cal.setYear(year);
cal.setCal(year,cal.getMonth()); }
else if(e.getSource()==showYear) {
try {
year=Integer.parseInt(showYear.getText()); showYear.setText(\ cal.setYear(year);
cal.setCal(year,cal.getMonth()); }
catch(NumberFormatException ee) {
showYear.setText(\ cal.setYear(year);
cal.setCal(year,cal.getMonth()); } } } }
//对备忘录的操作
package javaapplication13;
import java.awt.*;
import java.awt.event.*; import java.util.*; import javax.swing.*;
import javax.swing.event.*; import java.io.*;
public class NotePad extends JPanel implements ActionListener {
JTextArea text; JButton save_log,del_log; Hashtable table; JLabel mes_label; int year,month,day; File file;
CalendarPad calendar;
public NotePad(CalendarPad calendar)//构造函数 {
this.calendar=calendar;
Calendar now = Calendar.getInstance();
相关推荐: