我写一个 看看 呵呵
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
class MyDate extends JFrame{
Calendar now;
String temp;
int day_month[] = {31,29,31,30,31,30,31,31,30,31,30,31};
int first = 0;
JComboBox jcb_month;
JTextField year_jtf;
JPanel jpanel,jpanel_date;
JTextArea jta;
JLabel year_jlabel,month_jlabel;
MyDate(){
now = Calendar.getInstance();
jpanel = new JPanel();
year_jlabel = new JLabel("年");
year_jtf = new JTextField("2008");
jcb_month = new JComboBox(new String[]{"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"});
month_jlabel = new JLabel("月");
jpanel.add(year_jtf);
jpanel.add(year_jlabel);
jpanel.add(jcb_month);
jpanel.add(month_jlabel);
jpanel_date = new JPanel();
jta = new JTextArea();
jpanel_date.add(jta);
getContentPane().add(jpanel,BorderLayout.NORTH);
getContentPane().add(jpanel_date,BorderLayout.CENTER);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int now_year = now.get(Calendar.YEAR);
int now_month = now.get(Calendar.MONTH);
jcb_month.setSelectedIndex(now_month);
now.set(Calendar.DAY_OF_MONTH,1);
int now_day_of_week = now.get(Calendar.DAY_OF_WEEK);
int row_count = 0;
temp = "日
"+"一
" + "二
"+"三
"+"四
"+"五
"+"六
"+"\n";
for(int i=1;i<now_day_of_week;i++){
temp = temp + "
";
}
for(int j=1;j<=day_month[now_month];j++){
if( j < 10)
temp = temp + j + "
";
else
temp = temp + j +"
";
row_count ++;
if(row_count + now_day_of_week == 8 || row_count == 7){
temp = temp + "\n";
row_count= 0;
now_day_of_week = 0;
}
}
jta.append(temp);
temp = "";
ItemHandler handler = new ItemHandler();
jcb_month.addItemListener(handler);
}
class ItemHandler implements ItemListener{
public void itemStateChanged(ItemEvent e){
temp = "";
jta.setText("");
int row_count = 0;
temp = "日
"+"一
" + "二
"+"三
"+"四
"+"五
"+"六
"+"\n";
int selected_month = jcb_month.getSelectedIndex();
int get_year = Integer.parseInt(year_jtf.getText().trim());
now.set(Calendar.MONTH, selected_month);
now.set(Calendar.YEAR, get_year);
now.set(Calendar.DAY_OF_MONTH,1);
int day_of_week = now.get(Calendar.DAY_OF_WEEK);
for(int i=1;i<day_of_week;i++){
temp = temp + "
";
}
for(int j=1;j<=day_month[selected_month];j++){
if( j < 10)
temp = temp + j + "
";
else
temp = temp + j +"
";
row_count ++;
if(row_count + day_of_week == 8 || row_count == 7){
temp = temp + "\n";
row_count= 0;
day_of_week = 0;
}
}
jta.append(temp);
temp = "";
}
}
public static void main(String args[]){
new MyDate();
}
}