整理文件发现了大一的时候的作业,先感慨一波时间过得真的快!
手中的这个是一个独立的java文件,可以直接就可以运行,应该是没有什么问题的。不想这个代码就此落灰了,希望可以给友友们带来一点点帮助!
运行前命名为“CalendarDemo.java”并保存就可以运行。
运行界面结果如下:
日程提醒点击某一天就会弹出,填写即可:
?代码如下:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.Timer;
import java.lang.Integer;
import java.text.*;
import java.io.*;
public class CalendarDemo extends JFrame {
public static void main(String[] args) {
CalendarDemo cd = new CalendarDemo();
cd.show();
}
public CalendarDemo() {
setTitle("xxx的java作业");
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = screenSize.width/2;
int height = screenSize.height/2;
setSize(width, height);
setResizable(true);//窗体可变
setVisible(true);
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
JSplitPane splitPane = new JSplitPane();//分割
splitPane.setDividerLocation(500);
splitPane.setDividerSize(10);
CalendarPanel calenderPanel = new CalendarPanel(this);
ColockPanel colockPanel = new ColockPanel();
splitPane.setLeftComponent(calenderPanel);
splitPane.setRightComponent(colockPanel);
Container container = getContentPane();
container.add(splitPane);
new Thread(colockPanel).start();
}
}
//时钟面板
class ColockPanel extends JPanel implements Runnable,ActionListener{
private Label cur_clock, cur_week;
private JButton cur_day;
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);//去锯齿
g2d.setColor(Color.GRAY);
g2d.fillRect(0, 0, this.getWidth(), this.getHeight());
g2d.setColor(Color.GREEN);
int xCenter = this.getWidth() / 2;
int yCenter = this.getHeight() / 2;
int radius = (int) Math.min(this.getWidth(), this.getHeight() * 0.4); //计算半径
for (int i = 1; i <= 12; i++) {
double dd = (Math.PI * i) / 6;
int x = (int) (Math.sin(dd) * (radius - 20) + xCenter);
int y = (int) (yCenter - Math.cos(dd) * (radius - 20));
g2d.drawString(Integer.toString(i), x - 5, y + 7);
}
AffineTransform at = g2d.getTransform();
for (int i = 0; i < 60; i++) {
int w = i % 5 == 0 ? 3 : 1;
int h = i % 5 == 0 ? 8 : 5;
g2d.fillRect(xCenter - 2, yCenter - radius, w, h);//绘制矩形
g2d.rotate(Math.toRadians(6), xCenter, yCenter);
}
//获取时间
Calendar calendar = Calendar.getInstance();
int second = calendar.get(Calendar.SECOND);
int minute = calendar.get(Calendar.MINUTE);
int hour = calendar.get(Calendar.HOUR_OF_DAY);
Date currentTime = new Date();
SimpleDateFormat formatter_day = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat formatter_clock = new SimpleDateFormat("HH:mm:ss");
SimpleDateFormat format_week = new SimpleDateFormat("EEEE");
setFont(new Font("宋体", Font.PLAIN, 18));
g2d.drawString(format_week.format(currentTime), xCenter - 25, yCenter + (radius / 2));
g2d.drawString(formatter_clock.format(currentTime), xCenter - 35, yCenter + (radius / 3));
g2d.drawString(formatter_day.format(currentTime), xCenter - 40, yCenter - (radius / 2));
int xh = (int) (Math.sin(Math.PI / 360 * (60 * hour + minute)) * (radius / 2) + xCenter);
int yh = (int) (yCenter - (Math.cos(Math.PI / 360 * (60 * hour + minute)) * (radius / 2)));
int xm = (int) (Math.sin(Math.PI * minute / 30) * ((2 * radius) / 3) + xCenter);
int ym = (int) (yCenter - (Math.cos(Math.PI * minute / 30) * ((2 * radius) / 3)));
int xs = (int) (Math.sin(Math.PI * second / 30) * ((4 * radius) / 5) + xCenter);
int ys = (int) (yCenter - (Math.cos(Math.PI * second / 30) * ((4 * radius) / 5)));
//画时针,分针,秒针
g2d.setColor(Color.black);
g2d.setStroke(new BasicStroke(3.0f));
g2d.drawLine(xCenter, yCenter, xh, yh);
g2d.setStroke(new BasicStroke(2.0f));
g2d.drawLine(xCenter, yCenter, xm, ym);
g2d.setStroke(new BasicStroke(1.0f));
g2d.drawLine(xCenter, yCenter, xs, ys);
g2d.fillOval(xCenter - 5, yCenter - 5, 10, 10);
}
@Override
public void run() {
while (true) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
repaint(0,70,300,500);
}
}
@Override
public void actionPerformed(ActionEvent e) {
}
}
//日历面板
class CalendarPanel extends JPanel implements ActionListener {
private JPanel selectPanel;//月份减少按钮 ,选择月份 年份按钮,月份增加按钮
private JPanel showPanel;//该面板有三种显示状态,一种显示日历,一种显示选择月份,一种显示选择年份
private JPanel weekdayPanel;//该面板被添加到showPanel,用于静态显示周一到周日
private JPanel calshowPanel;//用于显示一月中的每一天
private JPanel selectMonth;
private JPanel selectYear;
private JButton btleft;
private JButton btmid;
private JButton btright;
private JFrame mainframe;
private JButton bt;
private TextField myText;
private Button[] btday = new Button[42];
private Button[] btmouth = new Button[12];
private Button[] btyear = new Button[12];
private Calendar curcalendar;//记录当前日历上显示的日期
private JFrame jFrame;
public CalendarPanel(JFrame jFrame) {
this.jFrame = jFrame;
setLayout(null);//设置布局为null
setBackground(new Color(143, 241, 219));
selectPanel = new JPanel();
selectPanel.setBackground(new Color(193, 241, 151));
selectPanel.setBounds(0, 0, 500, 50);
selectPanel.setLayout(null);
add(selectPanel);
btleft = new JButton("<");
btleft.setBounds(50, 10, 50, 30);
btleft.addActionListener(this);
selectPanel.add(btleft);
btmid = new JButton("");
btmid.setBounds(175, 10, 150, 30);
btmid.addActionListener(this);
selectPanel.add(btmid);
btright = new JButton(">");
btright.setBounds(400, 10, 50, 30);
btright.addActionListener(this);
selectPanel.add(btright);
weekdayPanel = new JPanel();
weekdayPanel.setBounds(0, 0, 490, 20);
weekdayPanel.setBackground(new Color(83, 199, 241));
weekdayPanel.setLayout(new GridLayout(1, 7));
weekdayPanel.setBorder(BorderFactory.createLineBorder(Color.black));
weekdayPanel.add(new JLabel("日", JLabel.CENTER));
weekdayPanel.add(new JLabel("一", JLabel.CENTER));
weekdayPanel.add(new JLabel("二", JLabel.CENTER));
weekdayPanel.add(new JLabel("三", JLabel.CENTER));
weekdayPanel.add(new JLabel("四", JLabel.CENTER));
weekdayPanel.add(new JLabel("五", JLabel.CENTER));
weekdayPanel.add(new JLabel("六", JLabel.CENTER));
calshowPanel = new JPanel();
calshowPanel.setBounds(0, 130, 500,430);
calshowPanel.setLayout(new GridLayout(6, 7));
for (int i = 0; i < 42; i++) {
btday[i] = new Button();
btday[i].setBackground(new Color(202,211,221));
btday[i].setFont(new Font("宋体", 4, 14));
btday[i].addActionListener(this);
}
curcalendar = Calendar.getInstance();
int monthday = curcalendar.get(Calendar.DAY_OF_MONTH);
int weekday = curcalendar.get(Calendar.DAY_OF_WEEK);
int startcol = 7 - (monthday - weekday) % 7;//当月第一天是一个星期中的第几天
if (startcol > 7) {
startcol = startcol%7;
}
System.out.println(startcol);
String midbt_lab = curcalendar.get(Calendar.YEAR) + "年" + (curcalendar.get(Calendar.MONTH) + 1) + "月";
btmid.setText(midbt_lab);
Calendar lastcalendar = (Calendar) curcalendar.clone();
lastcalendar.set(Calendar.DAY_OF_MONTH, 1);
lastcalendar.add(Calendar.DAY_OF_MONTH, -startcol);
int tablestart = lastcalendar.get(Calendar.DAY_OF_MONTH);//该页日历起始时是当月的第几天
int k = 0;
for (int i = 0; i < startcol; i++) {
btday[k].setForeground(Color.GRAY);
btday[k].setLabel((tablestart++) + "");
calshowPanel.add(btday[k++]);
}
for (int i = 1; i <= curcalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
btday[k].setForeground(Color.black);
btday[k].setLabel(i + "");
if (curcalendar.get(Calendar.DAY_OF_MONTH) == i-4) {
btday[i].setBackground(new Color(255, 255, 255));
}
calshowPanel.add(btday[k++]);
}
for (int i = 1; i <= 42 - startcol - curcalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
btday[k].setForeground(Color.GRAY);
btday[k].setLabel(i + "");
calshowPanel.add(btday[k++]);
}
showPanel = new JPanel();
showPanel.setBounds(0, 50, 500, 450);
showPanel.setLayout(new BorderLayout());
showPanel.setBorder(BorderFactory.createLineBorder(Color.black));
showPanel.add(weekdayPanel, BorderLayout.NORTH);
showPanel.add(calshowPanel, BorderLayout.CENTER);
add(showPanel);
selectMonth = new JPanel(new GridLayout(3, 4)); //选择月份
selectMonth.setBounds(0, 70, 500, 370);
for (int i = 0; i < 12; i++) {
btmouth[i] = new Button((i + 1) + "月");
btmouth[i].addActionListener(this);
btmouth[i].setBackground(new Color(202,211,221));
btmouth[i].setFont(new Font("Dialog",5,18));
selectMonth.add(btmouth[i]);
}
selectYear = new JPanel(new GridLayout(3, 4));//选择年份
selectYear.setBounds(0, 45, 500, 400);
for (int i = 0; i < 12; i++) {
btyear[i] = new Button((curcalendar.get(Calendar.YEAR) - 6 + i) + "");
btyear[i].addActionListener(this);
btyear[i].setBackground(new Color(202,211,221));
btyear[i].setFont(new Font("Dialog",5,18));
selectYear.add(btyear[i]);
}
}
//更新日历方法
private void updatebtday() {
int monthday = curcalendar.get(Calendar.DAY_OF_MONTH);//当前日期(在一月中的第几天)
int weekday = curcalendar.get(Calendar.DAY_OF_WEEK);//(在一周中的第几天)
int startcol = 7 - (monthday - weekday) % 7;//第一天是星期几
if (startcol > 7) {
startcol = startcol%7;
}
Calendar lastcalendar = (Calendar) curcalendar.clone();
lastcalendar.set(Calendar.DAY_OF_MONTH, 1);
lastcalendar.add(Calendar.DAY_OF_MONTH, -startcol);
int tablestart = lastcalendar.get(Calendar.DAY_OF_MONTH);
String midbt_lab = curcalendar.get(Calendar.YEAR) + "年" + (curcalendar.get(Calendar.MONTH) + 1) + "月";
btmid.setText(midbt_lab);
int k = 0;
for (int i = 0; i < startcol; i++) {
btday[k].setForeground(Color.GRAY);
btday[k++].setLabel((tablestart++) + "");
}
for (int i = 1; i <= curcalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
btday[k].setForeground(Color.black);
btday[k++].setLabel(i + "");
}
for (int i = 1; i <= 42 - startcol - curcalendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
btday[k].setForeground(Color.GRAY);
btday[k++].setLabel(i + "");
}
}
private int parseTime(String str) throws ParseException{
int i = 0, months=0,days=0;
int ch;
ch = str.charAt(i);
while (i < str.length() && ch != '-') {
if (ch < '0' || ch > '9') throw new ParseException(str, i);
months= months*10+ch - '0';
i++;
if (i < str.length())
ch = str.charAt(i);
else
throw new ParseException(str, i);
}
i++;
ch = str.charAt(i);
while (i < str.length() ) {
if (ch < '0' || ch > '9') throw new ParseException(str, i);
days=days*10+ch - '0';
i++;
if (i < str.length())
ch = str.charAt(i);
}
if (months > 12 || days>31) throw new ParseException(str, i);
return months*30+days;
}
public String TimeToString(Date day) {
Formatter fmt = new Formatter();
fmt.format("%tF"+" "+"%tT",day,day);
return fmt.toString();
}
JLabel component1=new JLabel("");
JTextField component3=new JTextField("");
int times;
class refresh extends TimerTask{
int i=0;
public refresh(){
super();
}
public void run(){
Date day=new Date();
TimeToString(day);
component1.setText(TimeToString(day));
i++;
if(i==3600*24){
times--;
i-=3600*24;
}
}
}
public void show(){
JFrame jf=new JFrame("日程");
jf.setSize(450,300);
jf.setLocationRelativeTo(null);
jf.setDefaultCloseOperation(3);
jf.setResizable(false);
Date today = new Date();
JTextField component14=new JTextField();
JLabel component15=new JLabel("地点");
JLabel component4=new JLabel("指定日期");
JTextField component5=new JTextField("00:00-24:00");
JLabel component6=new JLabel("提醒时间");
JTextField component7=new JTextField();
JLabel component8=new JLabel("事件");
JButton component9=new JButton("清空内容");
JButton component10=new JButton("确定");
JButton component11=new JButton("取消");
JCheckBox component12=new JCheckBox("弹窗提醒");
JLabel component2=new JLabel("倒计时"+" "+"天");
GridBagLayout gridBagLayout=new GridBagLayout(); //实例化布局对象
jf.setLayout(gridBagLayout); //jf窗体对象设置为GridBagLayout布局
GridBagConstraints gridBagConstraints=new GridBagConstraints();//实例化这个对象用来对组件进行管理
gridBagConstraints.fill=GridBagConstraints.BOTH;//BOTH实现填充
component9.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
component7.setText("");
}
});
component11.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
jf.setVisible(false);
}
});
component10.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent e) {
int endtime;
int curtime=(today.getMonth()+1)*30+today.getDate();
try{endtime=parseTime(component3.getText())-curtime;
times=endtime;
component2.setText("倒计时"+" "+endtime+" "+"天");
if(endtime==0&&component12.isSelected()) jf.setState(JFrame.NORMAL);
else jf.setState(JFrame.ICONIFIED);
}catch(ParseException el){
JOptionPane.showMessageDialog(jf, "指定日期有错误");
}
}
});
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=3;
gridBagConstraints.gridwidth=2;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component14, gridBagConstraints);
gridBagConstraints.gridx=3;
gridBagConstraints.gridy=3;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component15, gridBagConstraints);
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=2;
gridBagConstraints.gridwidth=4;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component1, gridBagConstraints);
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=4;
gridBagConstraints.gridwidth=2;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component3, gridBagConstraints);
gridBagConstraints.gridx=3;
gridBagConstraints.gridy=4;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component4, gridBagConstraints);
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=5;
gridBagConstraints.gridwidth=2;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component5, gridBagConstraints);
gridBagConstraints.gridx=3;
gridBagConstraints.gridy=5;
gridBagConstraints.gridwidth=2;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component6, gridBagConstraints);
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=6;
gridBagConstraints.gridwidth=4;
gridBagConstraints.gridheight=4;
gridBagLayout.setConstraints(component7, gridBagConstraints);
gridBagConstraints.gridx=5;
gridBagConstraints.gridy=6;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component8, gridBagConstraints);
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=10;
gridBagConstraints.gridwidth=2;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component9, gridBagConstraints);
gridBagConstraints.gridx=4;
gridBagConstraints.gridy=10;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component2, gridBagConstraints);
gridBagConstraints.gridx=1;
gridBagConstraints.gridy=11;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component10, gridBagConstraints);
gridBagConstraints.gridx=2;
gridBagConstraints.gridy=11;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component11, gridBagConstraints);
gridBagConstraints.gridx=4;
gridBagConstraints.gridy=11;
gridBagConstraints.gridwidth=1;
gridBagConstraints.gridheight=1;
gridBagLayout.setConstraints(component12, gridBagConstraints);
jf.add(component1);
jf.add(component14);
jf.add(component15);
jf.add(component2);
jf.add(component3);
jf.add(component4);
jf.add(component5);
jf.add(component6);
jf.add(component7);
jf.add(component8);
jf.add(component9);
jf.add(component10);
jf.add(component11);
jf.add(component12);
jf.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btmid) {//中间按钮
JPanel getPanel = (JPanel) showPanel.getComponent(0);
if (getPanel == weekdayPanel) {
btmid.setText(curcalendar.get(Calendar.YEAR) + "");
showPanel.removeAll();
showPanel.add(selectMonth);
} else if (getPanel == selectMonth){
showPanel.removeAll();
showPanel.add(selectYear);
btmid.setText((curcalendar.get(Calendar.YEAR) - 6) + "-" + (curcalendar.get(Calendar.YEAR) + 5));
}
jFrame.setVisible(true);
} else if (e.getSource() == btleft) {//左边按钮
JPanel getPanel = (JPanel) showPanel.getComponent(0);//获取容器中的第1个组件
if (getPanel == weekdayPanel) {
int month1 = curcalendar.get(Calendar.MONTH);
curcalendar.set(Calendar.MONTH, month1 - 1);
updatebtday();
} else if (getPanel == selectMonth) {
int year = curcalendar.get(Calendar.YEAR);
curcalendar.set(Calendar.YEAR, year - 1);
btmid.setText(curcalendar.get(Calendar.YEAR) + "");
} else {
String str = btyear[0].getLabel();
int first = Integer.parseInt(str);
for (int i = 11; i >= 0; i--) {
btyear[i].setLabel((--first) + "");
}
btmid.setText(first + "-" + (first + 11));
}
} else if (e.getSource() == btright) {
JPanel getPanel = (JPanel) showPanel.getComponent(0);
if (getPanel == weekdayPanel) {//如得到的组件是星期Panel,那么更新日历
int month1 = curcalendar.get(Calendar.MONTH);
curcalendar.set(Calendar.MONTH, month1 + 1);
updatebtday();
} else if (getPanel == selectMonth) {//如果得到的组件是月份的Panel,那么更新年份
int year = curcalendar.get(Calendar.YEAR);
curcalendar.set(Calendar.YEAR, year + 1);
btmid.setText(curcalendar.get(Calendar.YEAR) + "");
} else { //如果是选择年份界面,那么改变年份和mid按钮
String str = btyear[11].getLabel();
int last = Integer.parseInt(str);
for (int i = 0; i < 12; i++) {
btyear[i].setLabel((++last) + "");
}
btmid.setText((last - 11) + "-" + last);
}
} else if (((Button) e.getSource()).getForeground() == Color.GRAY) {//如果发生事件的为灰色按钮
String command = e.getActionCommand();
int com_int = Integer.parseInt(command);
if (com_int > 20) {//大于20表明是上个月的,设置月份,调用更新月份的方法
int month3 = curcalendar.get(Calendar.MONTH);
curcalendar.set(Calendar.MONTH, month3 - 1);
} else if (com_int < 20) {//小于20为下个月的
int month3 = curcalendar.get(Calendar.MONTH);
curcalendar.set(Calendar.MONTH, month3 + 1);
}
updatebtday();
} else if (((Button) e.getSource()).getForeground() == Color.black) {
show();
String str = e.getActionCommand();
component3.setText("01"+'-'+str);
Date d = new Date();
Timer tmr = new Timer();
tmr.schedule(new refresh(),1000,1000);
((Button) e.getSource()).setBackground(Color.RED);
} else if (e.getSource() == btyear[0]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[1]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[2]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[3]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[4]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[5]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[6]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[7]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[8]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[9]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[10]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else if (e.getSource() == btyear[11]) {
String str = e.getActionCommand();
int year = Integer.parseInt(str);
curcalendar.set(Calendar.YEAR, year);
showPanel.removeAll();
showPanel.add(selectMonth);
btmid.setText(str);
} else {
switch (e.getActionCommand()) {
case "1月":
curcalendar.set(Calendar.MONTH, 0);
break;
case "2月":
curcalendar.set(Calendar.MONTH, 1);
break;
case "3月":
curcalendar.set(Calendar.MONTH, 2);
break;
case "4月":
curcalendar.set(Calendar.MONTH, 3);
break;
case "5月":
curcalendar.set(Calendar.MONTH, 4);
break;
case "6月":
curcalendar.set(Calendar.MONTH, 5);
break;
case "7月":
curcalendar.set(Calendar.MONTH, 6);
break;
case "8月":
curcalendar.set(Calendar.MONTH, 7);
break;
case "9月":
curcalendar.set(Calendar.MONTH, 8);
break;
case "10月":
curcalendar.set(Calendar.MONTH, 9);
break;
case "11月":
curcalendar.set(Calendar.MONTH, 10);
break;
case "12月":
curcalendar.set(Calendar.MONTH, 11);
break;
}
showPanel.removeAll();
updatebtday();
showPanel.add(weekdayPanel,BorderLayout.NORTH);
showPanel.add(calshowPanel,BorderLayout.CENTER);
jFrame.setVisible(true);
}
}
}
可能会存在一点bug,不过影响应该不大,希望可以起到微薄帮助!?加油!