| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 801 人关注过本帖
标题:这个程序怎样用JOptionPane.showMessageDialog输出啊?
取消只看楼主 加入收藏
liang8768
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2009-9-2
收藏
 问题点数:0 回复次数:0 
这个程序怎样用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 ;
    }
}
搜索更多相关主题的帖子: 输出 JOptionPane 
2009-10-14 09:33
快速回复:这个程序怎样用JOptionPane.showMessageDialog输出啊?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040588 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved