import java.awt.BorderLayout;
import java.awt.Choice;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class Calandor extends JFrame implements ItemListener {
private int sum=0,sum1=0,sum2=0;
long longTime;
long currentTime;
long distTime;
long day ,hour,minutes,seconds;
Choice chYear = new Choice();
Choice chMonth = new Choice();
Choice chDay = new Choice();
JLabel ly = new JLabel("年");
JLabel lm = new JLabel("月");
JLabel ld = new JLabel("日");
JLabel ls = new JLabel("倒计时");
JTextField tf = new JTextField(20);
JLabel[] titleLabel = new JLabel[7];
JLabel[] dayLabel = new JLabel[42];
JPanel pn = new JPanel();
JPanel pc = new JPanel();
JPanel pb = new JPanel();
public Calandor() {
super("倒计时日历");
setLocation(300, 300);
initCenter();
initNorth();
initSouth();
add(pn, BorderLayout.NORTH);
add(pc, BorderLayout.CENTER);
add(pb, BorderLayout.SOUTH);
chYear.addItemListener(this);
chMonth.addItemListener(this);
chDay.addItemListener(this);
setCalendar();
pack();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void setCalendar() {
// TODO Auto-generated method stub
int year = Integer.parseInt(chYear.getSelectedItem());
int month = Integer.parseInt(chMonth.getSelectedItem());
int day = Integer.parseInt(chDay.getSelectedItem());
jiSuan();
/* for(int i=year1;i<year;i++){
if(i%400==0 || i%4==0 && i%100!=0){
sum+=366;
}else{
sum+=365;
}
System.out.println("sum = "+sum);
}
//System.out.println("sum = "+sum);
for(int j=month-1 ; j>0 ; j--){
int days = getMonthDays(year, month);
sum1+=sum1;
}
System.out.println("sum1 = "+sum1);
System.out.println("day2= "+day);
sum2=sum+sum1+day;
System.out.println("sum2 = "+sum2);*/
Calendar cal = Calendar.getInstance();
cal.set(year, month - 1, 1);
int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
int days = getMonthDays(year, month);
for (int i = 0; i < dayLabel.length; i++) {
dayLabel[i].setText("");
}
int index = 1;
for (int i = dayOfWeek - 1; i < dayOfWeek + days - 1; i++) {
dayLabel[i].setText(String.valueOf(index));
index++;
}
}
public int getMonthDays(int year, int month) {
// TODO Auto-generated method stub
int[] m = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
if (month == 2 && (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)) {
return 29;
}
return m[month];
}
public void initSouth() {
// TODO Auto-generated method stub
pb.add(ls);
pb.add(tf);
}
public void initNorth() {
// TODO Auto-generated method stub
Calendar cal = Calendar.getInstance();
int year1 = cal.get(Calendar.YEAR);
int month1 = cal.get(Calendar.MONTH);
int date = cal.get(Calendar.DATE);
System.out.println(date);
for (int i = year1; i < year1 + 10; i++) {
chYear.add(String.valueOf(i));
}
chYear.select(String.valueOf(year1));
for (int i = 1; i < 13; i++) {
chMonth.add(String.valueOf(i));