这个程序怎样用JOptionPane.showMessageDialog输出啊?
import javax.swing.JOptionPane;public class PrintCalendar {
public static void main (String[] agrs) {
String yearString = JOptionPane.showInputDialog (
"输入完整的年份(e.g.,2001):");
int year = Integer.parseInt (yearString);
String monthString = JOptionPane.showInputDialog (
"输入月份(1-12):");
int month = Integer.parseInt (monthString);
printMonth (year,month);
}
static void printMonth (int year,int month){
printMonthTital (year,month);
printMonthBody (year,month);
}
static void printMonthTital (int year,int month){
System.out.println (" "+getMonthName (month) +" "+year);
System.out.println ("--------------------------------");
System.out.println (" Sun Mon Tue Wed Thu Fri Sat");
}
static String getMonthName (int month) {
String monthname = null;
switch ( month ) {
case 1 : monthname = "一月";break;
case 2 : monthname = "二月";break;
case 3 : monthname = "三月";break;
case 4 : monthname = "四月";break;
case 5 : monthname = "五月";break;
case 6 : monthname = "六月";break;
case 7 : monthname = "七月";break;
case 8 : monthname = "八月";break;
case 9 : monthname = "九月";break;
case 10 : monthname = "十月";break;
case 11 : monthname = "十一月";break;
case 12 : monthname = "十二月";
} return monthname;
}
static void printMonthBody (int year,int month) {
int startDay = getStartDay (year,month);
int numberOfDaysInMonth = getNumberOfDaysInMonth (year,month);
int i = 0;
for ( i=0;i<startDay;i++)
System.out.print (" ");
for ( i=1;i<=numberOfDaysInMonth;i++) {
if ( i<10 )
System.out.print (" "+i );
else
System.out.print (" "+i );
if ((i+startDay)%7==0)
System.out.println();
}
System.out.println();
}
static int getStartDay ( int year,int month ) {
int a = 0;
a=( getTotalNumberOfDays ( year,month ) + 3 ) % 7 ;
return a;
}
static int getNumberOfDaysInMonth ( int year, int month ){
int getNumberOfDaysInMonth=0;
if ( month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 )
getNumberOfDaysInMonth=31 ;
if ( month == 4 || month == 6 || month == 9 || month == 11 ) getNumberOfDaysInMonth=30 ;
if ( month == 2 )
if ( isLeapYear(year)==true ) getNumberOfDaysInMonth= 29;
else getNumberOfDaysInMonth= 28;
return getNumberOfDaysInMonth;
}
static int getTotalNumberOfDays ( int year,int month ) {
int i = 1800 ; int total = 0;
for ( i=1800;i<year;i++ )
if (isLeapYear( i )==true)
total+=366;
else total+=365;
for ( i=1;i<month;i++ )
total+=getNumberOfDaysInMonth ( year,i );
return total;
}
static boolean isLeapYear( int year ) {
if ( year%400 == 0 || ( year%4 == 0 && year%100 != 0) )
return true ;
else return false ;
}
}