Java Line Chengwanning (Gregorian + lunar + Festivals + time)

Source: Internet
Author: User

Java Line Chengwanning (Gregorian + lunar + Festivals + time)

Package Mycalendar;import Java.awt.canvas;import java.awt.color;import java.awt.font;import java.awt.Graphics; Import Java.text.simpledateformat;import Java.util.Calendar; Class Clock extends Canvas implements runnable{/** * */private static final long Serialversionuid = 3660    124045489727166L;    MainFrame MF;    Thread T;     String time;    Public Clock (MainFrame MF) {THIS.MF=MF;    SetSize (280,40);    SetBackground (Color.White);                T=new Thread (this);                        Instantiate thread T.start ();                    Call thread} public void Run () {while (true) {try{thread.sleep (1000);    Sleeps 1 seconds}catch (interruptedexception e) {System.out.println ("exception");    } this.repaint (100);    }} public void Paint (Graphics g) {font f=new font ("Arial", font.bold,16); SimpleDateFormat sdf=new SimpleDateFormat ("yyyy ' year ' MM ' DD ' Day ' HH:mm:ss");//Format time display type Calendar now=    Calendar.getinstance ();        Time=sdf.format (Now.gettime ()); Get the current dayPeriod and Time G.setfont (f);    G.setcolor (Color.Black);    g.DrawString (time,45,25); }}
Package Mycalendar;import Java.awt.color;import Java.text.parseexception;import java.text.simpledateformat;import    Java.util.calendar;import Java.util.date;public class Lunar {private int year;    private int month;    private int day;    Private Boolean leap;    Final static String chinesenumber[] = {"One", "two", "three", "four", "five", "six", "seven", "eight", "Nine", "Ten", "11", "12"};    static SimpleDateFormat Chinesedateformat = new SimpleDateFormat ("yyyy year mm DD day"); Final static long[] Lunarinfo = new long[] {0x04bd8, 0x04ae0, 0x0a570, 0x054d5, 0x0d260, 0x0d950, 0x16554, 0x056a0, 0x0 9ad0, 0x055d2, 0x04ae0, 0x0a5b6, 0x0a4d0, 0x0d250, 0x1d255, 0x0b540, 0x0d6a0, 0x0ada2, 0x095b0, 0x14977, 0x04970, 0x0a4b0, 0x0b4b5, 0x06a50, 0X06D40, 0x1ab54, 0x02b60, 0x09570, 0x052f2, 0x04970, 0x06566, 0x0d4a0, 0x0ea50, 0x06e95, 0 X05ad0, 0x02b60, 0x186e3, 0x092e0, 0x1c8d7, 0x0c950, 0x0d4a0, 0x1d8a6, 0x0b550, 0x056a0, 0X1A5B4, 0x025d0, 0x092d0, 0x 0D2B2, 0x0a950, 0x0b557, 0x06ca0, 0x0b550, 0x15355,0x04da0, 0x0a5d0, 0x14573, 0x052d0, 0x0a9a8, 0x0e950, 0x06aa0, 0x0aea6, 0x0ab50, 0x04b60, 0x0aae4, 0x0a570, 0x05260, 0 x0f263, 0x0d950, 0x05b57, 0x056a0, 0x096d0, 0x04dd5, 0x04ad0, 0x0a4d0, 0x0d4d4, 0x0d250, 0x0d558, 0x0b540, 0x0b5a0, 0x  195a6, 0x095b0, 0x049b0, 0x0a974, 0x0a4b0, 0x0b27a, 0x06a50, 0X06D40, 0x0af46, 0x0ab60, 0x09570, 0x04af5, 0x04970, 0x064b0, 0X074A3, 0x0ea50, 0x06b58, 0x055c0, 0x0ab60, 0x096d5, 0x092e0, 0x0c960, 0x0d954, 0x0d4a0, 0x0da50, 0x07552, 0x056a0, 0x0abb7, 0x025d0, 0x092d0, 0x0cab5, 0x0a950, 0x0b4a0, 0X0BAA4, 0X0AD50, 0x055d9, 0x04ba0, 0x0a5b0, 0x15176, 0 X052b0, 0x0a930, 0x07954, 0x06aa0, 0X0AD50, 0x05b52, 0x04b60, 0x0a6e6, 0x0a4e0, 0x0d260, 0x0ea65, 0x0d530, 0x05aa0  , 0X076A3, 0x096d0, 0x04bd7, 0x04ad0, 0x0a4d0, 0x1d0b6, 0x0d250, 0x0d520, 0X0DD45, 0x0b5a0, 0x056d0, 0X055B2, 0x049b0,    0x0a577, 0x0a4b0, 0x0aa50, 0x1b255, 0X06D20, 0x0ada0}; ====== the total number of days passed back to the lunar year final private static int yeardays (int y) {int i, sum =348;        for (i = 0x8000; i > 0x8; I >>= 1) {if ((lunarinfo[y-1900] & i)! = 0) sum + = 1;    } return (sum + leapdays (y)); //====== returns the number of days of the Lunar New Year leap month final private static int leapdays (int y) {if (Leapmonth (y) = 0) {if (l            UNARINFO[Y-1900] & 0x10000)! = 0) return 30;        else return 29;    } else return 0; //====== returns the lunar Y-year leap which month 1-12, no leap returns 0 final private static int leapmonth (int y) {return (int) (Lunarinfo[y-    1900] & 0xf); The total number of days that//====== returns the lunar y year m month final private static int monthdays (int y, int m) {if (lunarinfo[y-1900] & (0        x10000 >> m)) = = 0) return 29;    else return 30; //====== returns the Lunar New Year's zodiac final public String Animalsyear () {final string[] Animals = "Mouse", "ox", "Tiger"        , "Rabbit", "dragon", "Snake", "horse", "sheep", "monkey", "Chicken", "dog", "Pig"};    Return animals[(year-4)% 12];  }  ====== incoming month's offset returns Ganzhi, 0 = Koshien final private static String cyclicalm (int num) {final string[] Gan = new STR        Ing[]{"A", "B", "C", "Ding", "e", "own", "Geng", "Xin", "Ren", "GUI"};        Final string[] Zhi = new string[]{"Son", "ugly", "Yin", "Mao", "Chen", "WU", "noon", "not", "Shen", "unitary", "Xu", "Hai"};    Return (gan[num%] + zhi[num% 12]);        }//====== incoming offset returns Ganzhi, 0 = Koshien final public String cyclical () {int num = year-1900 + 36;    Return (Cyclicalm (num));        public static String getchinadaystring (int day) {string chineseten[] = {"Initial", "Ten", "20", "30"}; int n = day% 10 = = 0?        9:day% 10-1;        if (Day >) return "";        if (day = =) return "decade";    else return CHINESETEN[DAY/10] + chinesenumber[n];     }/** *//** * outgoing y year m month D day corresponding to the lunar calendar.     * YearCyl3: What is the difference between agriculture and 1864?     * MonCyl4: Since January 31, 1900, the number of leap months * DAYCYL5: The number of days difference from January 31, 1900, plus 40?  * @param cal * @return */  Public String getlunardate (int year_log, int month_log, int. day_log) {//@SuppressWarnings ("unused") int year        Cyl, moncyl, daycyl;        int leapmonth = 0;        String nowadays;        Date basedate = null;        Date Nowaday=null;        try {basedate = Chinesedateformat.parse ("January 31, 1900");  } catch (ParseException e) {e.printstacktrace (); To change body of catch statement use Options |        File Templates.        } nowadays=year_log+ "Year" +month_log+ "month" +day_log+ "Day";        try {nowaday = Chinesedateformat.parse (nowadays);  } catch (ParseException e) {e.printstacktrace (); To change body of catch statement use Options |        File Templates.        }//Find out and January 31, 1900 difference in days int offset = (int) ((Nowaday.gettime ()-basedate.gettime ())/86400000L);        Daycyl = offset + 40;        moncyl = 14; Use offset minus the number of days per lunar year//calculated on the day of the lunar calendar days//i The final result is the lunar year//offset is the day ordinal of the year intIyear, daysofyear = 0;            for (iyear = 1900; Iyear < 10000 && offset > 0; iyear++) {daysofyear = Yeardays (iyear);            Offset-= daysofyear;        Moncyl + = 12;            } if (offset < 0) {offset + = daysofyear;            iyear--;        Moncyl-= 12;        }//Lunar year = iyear;        yearcyl = iYear-1864; Leapmonth = Leapmonth (iyear);        Leap which month, 1-12 leap = false;        Offset by the current year, minus the number of days per month (lunar), to find out the day is the month of the first days of int imonth, daysofmonth = 0; for (imonth = 1; imonth < && offset > 0; imonth++) {//Leap month if (Leapmonth > 0 &amp                ;& Imonth = = (Leapmonth + 1) &&!leap) {--imonth;                Leap = true;            Daysofmonth = Leapdays (year);            } else Daysofmonth = Monthdays (year, imonth);            Offset-= Daysofmonth; Lift Leap Month if (leap && imonth = = (LeapmontH + 1)) leap = false;        if (!leap) moncyl++; }//offset is 0 o'clock, and the month you just calculated is the leap months, to correct if (offset = = 0 && leapmonth > 0 && imonth = = Leapmonth +            1) {if (leap) {leap = false;                } else {leap = true;                --imonth;            --moncyl;            }}//offset is less than 0 o'clock, also to correct if (offset < 0) {offset + = Daysofmonth;            --imonth;        --moncyl;        } month = Imonth;            Day = offset + 1;                if ((month) ==1) (&&day==1) {return "Spring Festival";                } else if ((month) ==1 &&day==15) {return "Yuanxiao";        } else if ((month) ==5) &&day==5 return "dragon Boat Festival";        else if ((month) ==8) &&day==15 return "Mid-Autumn Festival";    else if (day==1) return chinesenumber[month-1] + "month";            else return getchinadaystring (day);    } public String toString () {if (chinesenumber[month-1]== "one" &&getchinadaystring (day) = = "First day") return "Lunar Calendar" +year + "year";    else if (getchinadaystring (day) = = "The Day") return Chinesenumber[month-1] + "month";        else return getchinadaystring (day); Return year + "years" + (leap?)    "Leap": ") + chinesenumber[month-1] +" month "+ getchinadaystring (day); }}

Package Mycalendar;import Java.awt.borderlayout;import Java.awt.color;import java.awt.gridlayout;import Java.awt.toolkit;import Java.awt.event.actionevent;import Java.awt.event.actionlistener;import java.sql.Date; Import Java.util.calendar;import javax.swing.jcombobox;import Javax.swing.jframe;import Javax.swing.JLabel;import Javax.swing.jpanel;import Javax.swing.JButton;    Class MainFrame extends JFrame {/** * */private static final long serialversionuid = 1L;    JPanel panel = new JPanel (new BorderLayout ());    JPanel Panel1 = new JPanel ();    JPanel Panel2 = new JPanel (New GridLayout (7, 7));    JPanel panel3 = new JPanel ();    jlabel[] Label = new JLABEL[49];    JLabel Y_label = new JLabel ("year");    JLabel M_label = new JLabel ("month");    JComboBox com1 = new JComboBox ();        JComboBox COM2 = new JComboBox ();    JButton but1=new JButton ("last month");        JButton but2=new JButton ("next month");    int re_year, re_month;    int x_size, y_size;    String Year_num; Calendar now = Calendar.getinstance ();        Instantiate calendar MainFrame () {super ("perpetual calendar");        SetSize (600, 700);        x_size = (int) (Toolkit.getdefaulttoolkit (). Getscreensize (). getwidth ());        y_size = (int) (Toolkit.getdefaulttoolkit (). Getscreensize (). GetHeight ());        SetLocation ((x_size-300)/2, (Y_SIZE-350)/2);                Setdefaultcloseoperation (Jframe.exit_on_close);                Panel1.add (BUT1);        Panel1.add (Y_label);        Panel1.add (COM1);        Panel1.add (M_label);                Panel1.add (COM2);                 Panel1.add (BUT2); for (int i = 0; i < i++) {Label[i] = new JLabel ("", jlabel.center);//sets the displayed character to center Panel2.add        (Label[i]);        } panel3.add (New Clock (this));        Panel.add (Panel1, Borderlayout.north);        Panel.add (Panel2, Borderlayout.center);        Panel.add (Panel3, Borderlayout.south);        Panel.setbackground (Color.White);        Panel1.setbackground (Color.White); Panel2.setbacKground (Color.White);        Panel3.setbackground (Color.gray);        Init ();        But1.addactionlistener (New Anaction ());        But2.addactionlistener (New Anaction ());        Com1.addactionlistener (New Clockaction ());                Com2.addactionlistener (New Clockaction ());        Setcontentpane (panel);        SetVisible (TRUE);    Setresizable (FALSE);  } class Anaction implements ActionListener {public void actionperformed (ActionEvent e) {int c_year,                  C_month,c_week; C_month = Integer.parseint (Com2.getselecteditem (). toString ())-1; Get the current month and subtract 1, the month in the computer is 0-11 c_year = Integer.parseint (Com1.getselecteditem (). toString ())-1;                 Gets the current selected year if (E.getsource () ==but1) {if (c_month==0) {                 C_year=c_year-1;                 c_month=11;                          } else c_month=c_month-1;             } if (E.getsource () ==but2){if (c_month==11) {c_year=c_year+1;                 c_month=0;             } else c_month=c_month+1;             } com1.setselectedindex (C_year);             Com2.setselectedindex (C_month); C_year = Integer.parseint (Com1.getselecteditem (). toString ()); Gets the currently selected year C_month = Integer.parseint (Com2.getselecteditem (). toString ())-1; Get the current month and subtract 1, the month in the computer is 0-11 C_week = use (C_year, c_month); Call function use, get day of the week Resetday (C_week, C_year, C_month); Call function Resetday}}/* Class Nextaction implements ActionListener {public void Actionperfo                Rmed (ActionEvent arg0) {int c_year, c_month,c_week; C_month = Integer.parseint (Com2.getselecteditem (). toString ())-1; Get the current month and subtract 1, the month in the computer is 0-11 c_year = Integer.parseint (Com1.getselecteditem (). toString ()); Gets the current selected year if (c_month==11) {c_year=c_year+1;            c_month=0; } C_week = Use (C_year, c_month); Call function use, get day of the week Resetday (C_week, C_year, C_month); Call function Resetday}} */class Clockaction implements ActionListener {public void AC            Tionperformed (ActionEvent arg0) {int c_year, c_month, C_week; C_year = Integer.parseint (Com1.getselecteditem (). toString ()); Gets the currently selected year C_month = Integer.parseint (Com2.getselecteditem (). toString ())-1; Get the current month and subtract 1, the month in the computer is 0-11 C_week = use (C_year, c_month); Call function use, get day of the week Resetday (C_week, C_year, C_month);         Call function Resetday}} public void Init () {int year, month_num, First_day_num;         String log[] = {"Day", "one", "two", "three", "four", "five", "six"};        for (int i = 0; i < 7; i++) {Label[i].settext (log[i]); } for (int i = 0; i <; i = i + 7) {label[i].setforeground (Color.Blue);//SundayThe period is set to red} for (int i = 6; i <; i = i + 7) {label[i].setforeground (Color.Blue);//Set Saturday date        For Hong-color} for (int i = 1; i < 10000; i++) {Com1.additem ("" + i);        } for (int i = 1; i < i++) {Com2.additem ("" + i); } month_num = (int) (Now.get (Calendar.month)); Gets the current time of the month of year = (int) (Now.get (calendar.year)); Gets the current time of year Com1.setselectedindex (YEAR-1);        The Settings drop-down list is displayed as the current year??????????? Com2.setselectedindex (Month_num);        The Settings drop-down list is displayed for the current month First_day_num = use (year, month_num);    Resetday (First_day_num, year, month_num);        } public int use (int reyear, int remonth) {int week_num; Now.set (Reyear, Remonth, 1);    Set the time for the first day of the year you want to query week_num = (int) (Now.get (Calendar.day_of_week));//Get the first day of the week return week_num;             }//@SuppressWarnings ("deprecation") public void Resetday (int week_log, int year_log, int month_log) { IntMonth_day_score;        Number of days to store the month int count;        Lunar Lunar;        int month_day;                String[] Lunardate=new string[49];        Month_day_score = 0;                        Count = 1; for (int i = 1; i <; i + +) {for (int j=0;j<49;j=j+7) {if (i!=j&&i!=j+6) label         [I].setforeground (Color.Black); }} Date Date = new Date (Year_log, Month_log + 1, 1); Now month is starting from 0, for the first day of January, Day_of_month was 1.        For the first few months of the year, month January is 0, February is 1 ...        Calendar cal = Calendar.getinstance ();        Cal.settime (date); Cal.add (Calendar.month,-1);         Previous Month Month_day_score = Cal.getactualmaximum (calendar.day_of_month);//Last Day of Month_day=month_day_score;        for (int i = 7; I < i++) {//Initialize tag Label[i].settext (""); } Week_log = Week_log + 6;                Add 6 to the day of the week so that the display is correct month_day_score = Month_day_score + week_log;        Lunar=new lunar ();for (int i=0;i<month_day;i++) {lunardate[i]=lunar.getlunardate (Year_log, month_log+1, i+1); } for (int i = Week_log; i < Month_day_score; i++, count++) {if (month_log==9&am        P;&count==1) {Label[i].settext (count + "National Day");        Label[i].setforeground (color.red);        } else if (month_log==0&&count==1) {Label[i].settext (count + "New Year's Day");                Label[i].setforeground (color.red);        } else if (month_log==11&&count==24) {Label[i].settext (count + "Christmas Eve");                Label[i].setforeground (color.red);        } else if (month_log==11&&count==25) {Label[i].settext (count + "Christmas");        Label[i].setforeground (color.red);        } else if (month_log==1&&count==14) {Label[i].settext (count + "Valentine's Day");        Label[i].setforeground (color.red); } else if (month_log==4&&count==1) {Label[i].settext (count + "Labor Day");                Label[i].setforeground (color.red); } else if (Lunardate[i-week_log].equals ("Spring Festival") | | Lunardate[i-week_log].equals ("Yuanxiao") | | Lunardate[i-week_log].equals ("Dragon Boat Festival") | |        Lunardate[i-week_log].equals ("Mid-Autumn Festival")) {Label[i].settext (Count +lunardate[i-week_log]);        Label[i].setforeground (color.red);        } else Label[i].settext (Count +lunardate[i-week_log]);        }} public static void Main (string[] args) {jframe.setdefaultlookandfeeldecorated (true);    New MainFrame (); }}


The peak of the cupola 20160623

Java Line Chengwanning (Gregorian + lunar + Festivals + time)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.