Java Perpetual calendar and java Perpetual calendar code

Source: Internet
Author: User

Java Perpetual calendar and java Perpetual calendar code

Recently, I have been working hard to supplement the professional courses that have been delayed due to ACM.

Unfortunately .. You can only do this step by step.

Mycalender:

Import java. awt. *; public class mycalender {public static void main (String [] args) {WindowActionEvent win = new WindowActionEvent (); ReadListen listener = new ReadListen (); // create a monitor (listener can be any) Container con = win. getContentPane (); con. setBackground (Color. green); win. setMycommandListener (listener); // window combination monitor win. setTitle ("-- My perpetual calendar ---"); win. setBounds (100,100,610,560 );}}

WindowActionEvent:

Import java. awt. *; import javax. swing. *; import java. awt. event. *; public class WindowActionEvent extends JFrame {JTextField textInput; JTextArea textShow; JButton button; public WindowActionEvent () {init (); setVisible (true); setdefaclocloseoperation (JFrame. EXIT_ON_CLOSE);} void init () {// construction window setLayout (new FlowLayout (); add (new JLabel ("Enter the year you want to query (after January 1, 1900 ): "); textInput = new JTextField (15); add (textInput); button = new JButton (" OK "); add (button ); add (new JLabel ("the calendar of this year is:"); textShow = new JTextArea (); add (new JScrollPane (textShow);} void setMycommandListener (ReadListen listener) {listener. setJTextField (textInput); listener. setJTextArea (textShow); button. addActionListener (listener); // button is the event source, and listener is the monitor textInput. addActionListener (listener); // textInput is the event source, and listener is the monitor }}

ReadListen:

Import java. awt. event. *; import javax. swing. *; public class ReadListen implements ActionListener {JTextArea textShow; JTextField textInput; public void Merge (JTextArea area) {textShow = area;} public void setJTextField (JTextField text) {textInput = text ;} public void actionreceivmed (ActionEvent e) {double nowyears = Double. parseDouble (textInput. getText (); print (nowyears);} void print (double nowyears) {int da Y = 0, mon [] = {1990, 28, 31, 30, 31, 30, 31, 30, 31}; for (int year =; year <nowyears; year + +) {if (year % 4 = 0 & year % 100! = 0 | year % 400 = 0) day + = 366; elseday + = 365;} int week = (day + 1) % 7; textShow. setText ("1st month: \ n day \ t one \ t Two \ t three \ t four \ t five \ t six \ n "); if (nowyears % 4 = 0 & amp; nowyears % 100! = 0 | nowyears % 400 = 0) mon [2] = 29; elsemon [2] = 28; int Monday = 1; while (Monday <13) {int t = 1; if (week = 7) week = 0; for (int I = 0; I <week; I ++) textShow. append ("\ t"); while (t <= mon [Monday]) {if (week = 7) {week = 0; textShow. append ("\ n");} textShow. append (t + "\ t"); t ++; week ++;} textShow. append ("\ n"); Monday ++; if (Monday = 13) break; textShow. append ("nth" + Monday + "month: \ n"); textShow. append ("day \ t one \ t Two \ t three \ t four \ t five \ t six \ n ");}}}
Here is the running result:




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.