java萬年曆

來源:互聯網
上載者:User

標籤:java萬年曆   萬年曆   日曆   

最近一直在努力補因為ACM而耽誤的專業課,o(︶︿︶)o 唉 其實我也很喜歡C語言的。

可惜。。只能一步一步來。

Mycalender:

import java.awt.*;public class MycalCalender {public static void main(String[] args) {WindowActionEvent win=new WindowActionEvent();ReadListen listener=new ReadListen();//建立監視器(listener可以是任意的)Container con=win.getContentPane();con.setBackground(Color.green);win.setMycommandListener(listener);//視窗組合監視器win.setTitle("——我的萬年曆———");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);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}void init(){//構建視窗setLayout(new FlowLayout());add(new JLabel("請輸入你要查詢的年份(1900年以後):"));textInput=new JTextField(15);add(textInput);button=new JButton("確定");add(button);add(new JLabel("             這一年的日曆為:"));textShow=new JTextArea(25,51);add(new JScrollPane(textShow));}void setMycommandListener(ReadListen listener){listener.setJTextField(textInput);listener.setJTextArea(textShow);button.addActionListener(listener);//button是事件來源,listener是監視器textInput.addActionListener(listener);//textInput是事件來源,listener是監視器}}

ReadListen:

import java.awt.event.*;import javax.swing .*;public class ReadListen implements ActionListener{JTextArea textShow;JTextField textInput;public void setJTextArea(JTextArea area){textShow=area;}public void setJTextField(JTextField text){textInput=text;}public void actionPerformed(ActionEvent e){double nowyears=Double.parseDouble(textInput.getText());print(nowyears);}void print(double nowyears){int day=0,mon[]={0,31,28,31,30,31,30,31,31,30,31,30,31};for(int year=1990;year<nowyears;year++){if(year%4==0&&year%100!=0||year%400==0)day+=366;elseday+=365;}int week=(day+1)%7;textShow.setText("第1月:\n日\t一\t二\t三\t四\t五\t六\n");if(nowyears%4==0&&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("第"+monday+"月:\n");textShow.append("日\t一\t二\t三\t四\t五\t六\n");}}}
這是運行結果:




java萬年曆

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.