久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

java代碼萬年歷帶日,用java寫萬年歷

用java語言編寫萬年歷

給你一個現(xiàn)成的,我自己寫的。

成都創(chuàng)新互聯(lián)公司服務項目包括迪慶州網(wǎng)站建設、迪慶州網(wǎng)站制作、迪慶州網(wǎng)頁制作以及迪慶州網(wǎng)絡營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關系等,向廣大中小型企業(yè)、政府機構等提供互聯(lián)網(wǎng)行業(yè)的解決方案,迪慶州網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務的客戶以成都為中心已經(jīng)輻射到迪慶州省份的部分城市,未來相信會繼續(xù)擴大服務區(qū)域并繼續(xù)獲得客戶的支持與信任!

import java.awt.*;

import java.util.*;

import javax.swing.*;

import java.awt.event.*;

public class WanNianLi extends JFrame implements ActionListener {

private static int year,month,days;

private JButton[] btn=new JButton[days];

WanNianLi() {

super("萬年歷");

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

GridLayout bl=new GridLayout(5,7);

JPanel pane=new JPanel();

pane.setLayout(bl);

for (int i=0;idays;i++) {

int temp=i+1;

btn[i]=new JButton(""+temp);

btn[i].addActionListener(this);

pane.add(btn[i]);

}

setContentPane(pane);

pack();

setLookAndFeel();

setVisible(true);

}

public static void main(String[] args) {

if (args.length0)

year=Integer.parseInt(args[0]);

else

year=1982;

if (args.length1)

month=Integer.parseInt(args[1]);

else

month=1;

GetDays gd=new GetDays(year,month);

days=gd.getDays();

new WanNianLi();

}

public void actionPerformed(ActionEvent evt) {

Object src=evt.getSource();

for (int i=0;idays;i++)

if (src==btn[i]) {

int day=i+1;

GetWeekday gw=new GetWeekday(year,month,day);

String str="";

switch (gw.getWeekday()) {

case 1:

str="天";

break;

case 2:

str="一";

break;

case 3:

str="二";

break;

case 4:

str="三";

break;

case 5:

str="四";

break;

case 6:

str="五";

break;

case 7:

str="六";

break;

}

setTitle(year+"年"+month+"月"+day+"日"+"星期"+str);

repaint();

}

}

private void setLookAndFeel() {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

SwingUtilities.updateComponentTreeUI(this);

}catch(Exception e){

System.out.print(e.toString());

}

}

}

//////////////

//獲取星期幾//

//////////////

class GetWeekday {

private Calendar cal=Calendar.getInstance();

private static int weekday;

public int getWeekday() {

return weekday;

}

GetWeekday(int y,int m,int d) {

cal.clear();

cal.set(Calendar.YEAR,y);

cal.set(Calendar.MONTH,m-1);

cal.set(Calendar.DAY_OF_MONTH,d);

weekday=cal.get(Calendar.DAY_OF_WEEK);

}

}

////////////////////

//獲取當前月的天數(shù)//

////////////////////

class GetDays {

private static int days;

public int getDays() {

return days;

}

GetDays(int y,int m) {

GregorianCalendar gc=new GregorianCalendar();

switch (m) {

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days=31;

break;

case 4:

case 6:

case 9:

case 11:

days=30;

break;

case 2:

if (gc.isLeapYear(y))

days=29;

else

days=28;

break;

}

}

}

JAVA編寫一個多功能萬年歷程序

import java.text.SimpleDateFormat; import java.util.Calendar; public class TestDate { public static final String[] weeks = { "日", "一", "二", "三", "四", "五", "六" }; public static void main(String[] args) { Calendar c = Calendar.getInstance(); c.set(Calendar.YEAR,2011);//2011年 c.set(Calendar.MONTH,0);//java中Calendar類,月從0開始, 0代表一月 c.set(Calendar.DATE,1);//1號 int day = c.get(Calendar.DAY_OF_WEEK);//獲致是本周的第幾天地, 1代表星期天...7代表星期六 System.out.println(new SimpleDateFormat( "yyyy-MM-dd ").format(c.getTime())); System.out.println("星期" + weeks[day-1]); } } 把以上測試代碼寫作一個方法 方法的參數(shù)名為年月日, 即可。當然Calendar 還有很多功能,比如一周的第幾天,一年的第幾個月……

JAVA萬年歷代碼

/*

題目:輸出任意年份任意月份的日歷表(公元后)

思路:

1.已知1年1月1日是星期日,1?%?7?=?1?對應的是星期日,2?%?7?=?2?對應的是星期一,以此類推;

2.計算當年以前所有天數(shù)+當年當月1號之前所有天數(shù);

a.年份分平年閏年,平年365天,閏年366天;

b.閏年的判斷方法year?%?400?==?0?||?(year?%?100?!=?0??year?%?4?==?0)若為真,則為閏年否則為平年;

c.定義平年/閏年數(shù)組,包含各月天數(shù);

d.遍歷數(shù)組求和,計算當年當月前總天數(shù);

e.當年以前所有天數(shù)+當年當月前總天數(shù)+1即為1年1月1日到當年當月1日的總天數(shù);

3.總天數(shù)對7取模,根據(jù)結果判斷當月1號是星期幾,輸出空白區(qū)域;

4.輸出當月日歷表,逢星期六換行

*/

import?java.util.Scanner;

class?FindMonthList?{

public?static?void?main(String[]?args){

Scanner?sc?=?new?Scanner(System.in);

System.out.println("請輸入年份:");

int?year?=?sc.nextInt();????????????//年份

if?(year??1)?{????????????????????????//判斷非法輸入年份

System.out.println("輸入錯誤!");

return;

}

System.out.println("請輸入月份:");

int?month?=?sc.nextInt();????????????//月份

if?(month??1?||?month??12)?{????????//判斷非法輸入月份

System.out.println("輸入錯誤!");

return;

}

//輸出表頭

System.out.println("-------"?+?year?+?"?年?"?+?month?+?"?月?"?+?"-------");

System.out.println();

System.out.println("日??一??二??三??四??五??六");

//計算當前年份以前所有天數(shù)beforeYearTotalDay;每4年一個閏年,閏年366天,平年365天

int?beforeYearTotalDay?=?((year?-?1)?/?4?*?366)?+?(year-1?-?((year?-?1)?/?4))?*?365;

int[]?arrLeapYear?=?{0,31,29,31,30,31,30,31,31,30,31,30,31};????//閏年各月天數(shù)????int數(shù)組

int[]?arrNormalYear?=?{0,31,28,31,30,31,30,31,31,30,31,30,31};????//平年各月天數(shù)????int數(shù)組

int?beforeMonthTotalDay?=?0;????????????????????????????????????//定義本年當月之前月份的總天數(shù)

if?(year?%?400?==?0?||?(year?%?100?!=?0??year?%?4?==?0))?{????//判斷當前年份是否是閏年

for?(int?i?=?0?;?i??month?;?i?++?)?{????//for循環(huán)計算當月之前總天數(shù)

//計算當前月份之前的所有天數(shù)

beforeMonthTotalDay?=?beforeMonthTotalDay?+?arrLeapYear[i];

}

//判斷當月1日是星期幾

int?totalDay?=?beforeYearTotalDay?+?beforeMonthTotalDay?+?1;

int?week?=?totalDay?%?7;//已知1年1月1日是星期日,即模7得1對應的是星期日

for?(int?i?=?0?;?i??(week?-?1?+?7)?%?7?;?i?++)?{????//如果寫成i??(week-1)會出現(xiàn)i-1的情況

System.out.print("????");//輸出開頭空白

}

for?(int?i?=?1?;i?=?arrLeapYear[month]?;i?++?)?{????//for循環(huán)輸出各月天數(shù)

System.out.print(i?+?"??");

if?(i??10?)?{????????//小于10的數(shù)補一個空格,以便打印整齊

System.out.print("?");

}

if?(i?%?7?==?((7-(week?-?1))?%?7?)?||?i?==?arrLeapYear[month])?{//每逢星期六/尾數(shù)換行

System.out.println();

}

}

}?else?{????????//不是閏年就是平年

for?(int?i?=?0?;?i??month?;?i?++?)?{????//for循環(huán)計算出當月之前月份總天數(shù)

beforeMonthTotalDay?=?beforeMonthTotalDay?+?arrNormalYear[i];

}

//判斷當月1日是星期幾

int?totalDay?=?beforeYearTotalDay?+?beforeMonthTotalDay?+?1;

int?week?=?totalDay?%?7;//已知1年1月1日是星期日,即模7得1對應的是星期日

for?(int?i?=?0?;?i??(week?-?1?+?7)?%?7?;?i?++)?{????//如果寫成i??(week-1)會出現(xiàn)i-1的情況

System.out.print("????");//輸出開頭空白

}

for?(int?i?=?1?;i?=?arrNormalYear[month]?;i?++?)?{//for循環(huán)輸出各月天數(shù)

System.out.print(i?+?"??");

if?(i??10?)?{????????????//小于10的數(shù)補一個空格,以便打印整齊

System.out.print("?");

}

if?(i?%?7?==?((7-(week?-?1))?%?7?)?||?i?==?arrNormalYear[month])?{//每逢星期六/尾數(shù)換行

System.out.println();

}

}

}

}

}

顯示效果:

求一個java swing帶界面的萬年歷代碼

按照你的要求編寫的Java swing 帶界面的萬年歷代碼如下

//日歷

import?java.awt.BorderLayout;

import?java.awt.Color;

import?java.awt.Font;

import?java.awt.GridLayout;

import?java.awt.event.ActionEvent;

import?java.awt.event.ActionListener;

import?java.util.Calendar;

import?javax.swing.BorderFactory;

import?javax.swing.JButton;

import?javax.swing.JFrame;

import?javax.swing.JLabel;

import?javax.swing.JPanel;

public?class?CCI?extends?JFrame?implements?ActionListener{

JButton?jb1=new?JButton("");

JButton?jb2=new?JButton("");

JButton?jb3=new?JButton("");

JButton?jb4=new?JButton("");

JPanel?jp1=new?JPanel();

JPanel?jp2=new?JPanel();

JPanel?jp3=new?JPanel();

JPanel?jp4=new?JPanel();

JLabel?jl1=new?JLabel();

JLabel?jl2=new?JLabel();

JLabel[]jl=new?JLabel[49];

String?[]week={"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};

Calendar?c=Calendar.getInstance();

int?year,month,day;

int?nowyear,nowmonth,nowday;

CCI(){

super("簡單日歷");

nowyear=c.get(Calendar.YEAR);

nowmonth=c.get(Calendar.MONTH)+1;

nowday=c.get(Calendar.DAY_OF_MONTH);

year=nowyear;

month=nowmonth;

day=nowday;

String?s=year+"年"+month+"月";

jl1.setForeground(Color.RED);

jl1.setFont(new?Font(null,Font.BOLD,20));

jl1.setText(s);

jb1.addActionListener(this);

jb2.addActionListener(this);

jb3.addActionListener(this);

jb4.addActionListener(this);

jp1.add(jb1);jp1.add(jb2);jp1.add(jl1);jp1.add(jb3);jp1.add(jb4);

jp2.setLayout(null);

createMonthPanel();

jp2.add(jp3);

jl2.setFont(new?Font(null,Font.BOLD,20));

jl2.setText("今天是"+nowyear+"年"+nowmonth+"月"+nowday+"日");

jp4.add(jl2);

add(jp1,BorderLayout.NORTH);

add(jp2,BorderLayout.CENTER);

add(jp4,BorderLayout.SOUTH);

setSize(500,500);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLocationRelativeTo(null);

setVisible(true);

}

@Override

public?void?actionPerformed(ActionEvent?ae)?{

if(ae.getSource()==jb1){

year=year-1;

String?s=year+"年"+month+"月";

jl1.setText(s);

jp3.removeAll();

createMonthPanel();

jp3.validate();

}

if(ae.getSource()==jb2){

if(month==1){

year=year-1;

month=12;

}else{

month=month-1;

}

String?s=year+"年"+month+"月";

jl1.setText(s);

jp3.removeAll();

createMonthPanel();

jp3.validate();

}

if(ae.getSource()==jb3){

if(month==12){

year=year+1;

month=1;

}else{

month=month+1;

}

String?s=year+"年"+month+"月";

jl1.setText(s);

jp3.removeAll();

createMonthPanel();

jp3.validate();

}

if(ae.getSource()==jb4){

year=year+1;

String?s=year+"年"+month+"月";

jl1.setText(s);

jp3.removeAll();

createMonthPanel();

jp3.validate();

}

}

public?static?void?main(String[]?args)?{

new?CCI();

}

public?int?getMonthDays(int?year,?int?month)?{?

switch?(month)?{

case?1:?

case?3:?

case?5:?

case?7:

case?8:?

case?10:?

case?12:

return?31;?

case?2:?

if?((year%4==0year%100!=0)||year%400==0)?{?

return?29;?

}?else?{?

return?28;?

}?

default:?

return?30;?

}?

}?

public?void?createMonthPanel(){

c.set(year,?month-1,?getMonthDays(year,month));

int?weekOfMonth=c.get(Calendar.WEEK_OF_MONTH);

if(weekOfMonth==6){

jp3.setLayout(new?GridLayout(7,7));

jp3.setBounds(50,?20,?420,?350);

}else{

jp3.setLayout(new?GridLayout(6,7));

jp3.setBounds(50,?20,?420,?300);

}

jp3.setBorder(BorderFactory.createEtchedBorder());

for(int?i=0;i7;i++){

jl[i]=new?JLabel(week[i],JLabel.CENTER);

jl[i].setFont(new?Font(null,Font.BOLD,20));

jl[i].setBorder(BorderFactory.createEtchedBorder());

jp3.add(jl[i]);

}

c.set(year,?month-1,?1);

int?emptyFirst=c.get(Calendar.DAY_OF_WEEK)-1;

int?daysOfMonth=getMonthDays(year,month);

for(int?i=6+emptyFirst;i=7;i--){

int?intyear=year;

int?intmonth=month;

if(intmonth==1){

intyear=intyear-1;

intmonth=12;

}else{

intmonth=intmonth-1;

}

int?intdays=getMonthDays(intyear,intmonth);

jl[i]=new?JLabel((intdays+7-i)+"",JLabel.CENTER);

jl[i].setFont(new?Font(null,Font.BOLD,20));

jl[i].setForeground(Color.GRAY);

jl[i].setBorder(BorderFactory.createEtchedBorder());

jp3.add(jl[i]);

}

for(int?i=7+emptyFirst;idaysOfMonth+7+emptyFirst;i++){

jl[i]=new?JLabel((i-7-emptyFirst+1)+"",JLabel.CENTER);

jl[i].setFont(new?Font(null,Font.BOLD,20));

if((i+1)%7==0?||?(i+1)%7==1){

jl[i].setForeground(Color.RED);

}else?if((i-7-emptyFirst+1)==nowdaymonth==nowmonthyear==nowyear)

jl[i].setForeground(Color.BLUE);

else

jl[i].setForeground(Color.BLACK);

jl[i].setBorder(BorderFactory.createEtchedBorder());

jp3.add(jl[i]);

}

if(weekOfMonth==6)

for(int?i=48;i=daysOfMonth+emptyFirst+7;i--){

jl[i]=new?JLabel((49-i)+"",JLabel.CENTER);

jl[i].setFont(new?Font(null,Font.BOLD,20));

jl[i].setForeground(Color.GRAY);

jl[i].setBorder(BorderFactory.createEtchedBorder());

jp3.add(jl[i]);

}

else

for(int?i=41;i=daysOfMonth+emptyFirst+7;i--){

jl[i]=new?JLabel((42-i)+"",JLabel.CENTER);

jl[i].setFont(new?Font(null,Font.BOLD,20));

jl[i].setForeground(Color.GRAY);

jl[i].setBorder(BorderFactory.createEtchedBorder());

jp3.add(jl[i]);

}

}

}

如何用java語言 寫出一個萬年歷呢? 要求自己輸入年份 自動出現(xiàn)月 日 以及對應的星期

如果要月歷,只要把月份循環(huán)那里修改下,直接調(diào)用月歷方法既可

import java.text.DateFormatSymbols;

import java.util.Calendar;

import javax.swing.JOptionPane;

public class YearCalendar {

public static void main(String[] args) {

final String title = getCalTitle();

String input = JOptionPane.showInputDialog("Please input year");

try{

if(!input.trim().matches("^\\d{4}$")){

throw new NumberFormatException();

}

int year = Integer.parseInt(input.trim());

System.out.println("------- Calendar For Year " + year + " ----------------");

String[] monthTitles = new DateFormatSymbols().getMonths();

for(int month = Calendar.JANUARY; month = Calendar.DECEMBER; month++){

System.out.println("\t********** " + monthTitles[month] + " *********");

System.out.println(title);

generateMonthlyCalendar(year, month);

System.out.println("\n\n");

}

}catch(NumberFormatException nbFmtExp){

JOptionPane.showMessageDialog(null, "Error data foramt! Date should be 4 digits only format yyyy");

System.exit(0);

}

}

private static String getCalTitle() {

StringBuffer sb = new StringBuffer();

String[] ary = new DateFormatSymbols().getShortWeekdays();

for(int i = Calendar.SUNDAY; i = Calendar.SATURDAY; i++){

sb.append(ary[i]+ "\t");

}

return sb.toString();

}

private static void generateMonthlyCalendar(int year, int month) {

Calendar cal = Calendar.getInstance();

cal.set(Calendar.YEAR, year);

cal.set(Calendar.MONTH, month);

cal.set(Calendar.DATE, 1);

int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);

int i = 0;

for(i = Calendar.SUNDAY; i cal.get(Calendar.DAY_OF_WEEK); i++){

System.out.print(" \t");

}

while(cal.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY){

System.out.print(cal.get(Calendar.DATE) + "\t");

cal.add(Calendar.DATE, 1);

}

int weekDay = Calendar.SATURDAY;

int day = cal.get(Calendar.DATE);

while(day = maxDay){

if(weekDay == Calendar.SATURDAY){

System.out.println();

weekDay = Calendar.SUNDAY;

}else{

weekDay++;

}

System.out.print(day++ + "\t");

}

}

}

--------------------------------JDK 1.5結果

------- Calendar For Year 2011 ----------------

********** January *********

Sun Mon Tue Wed Thu Fri Sat

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30 31

********** February *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28

********** March *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28 29 30 31

********** April *********

Sun Mon Tue Wed Thu Fri Sat

1 2

3 4 5 6 7 8 9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

********** May *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

********** June *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4

5 6 7 8 9 10 11

12 13 14 15 16 17 18

19 20 21 22 23 24 25

26 27 28 29 30

********** July *********

Sun Mon Tue Wed Thu Fri Sat

1 2

3 4 5 6 7 8 9

10 11 12 13 14 15 16

17 18 19 20 21 22 23

24 25 26 27 28 29 30

31

********** August *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5 6

7 8 9 10 11 12 13

14 15 16 17 18 19 20

21 22 23 24 25 26 27

28 29 30 31

********** September *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30

********** October *********

Sun Mon Tue Wed Thu Fri Sat

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30 31

********** November *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3 4 5

6 7 8 9 10 11 12

13 14 15 16 17 18 19

20 21 22 23 24 25 26

27 28 29 30

********** December *********

Sun Mon Tue Wed Thu Fri Sat

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30 31

文章名稱:java代碼萬年歷帶日,用java寫萬年歷
轉(zhuǎn)載注明:http://sd-ha.com/article26/hooicg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設品牌網(wǎng)站設計、搜索引擎優(yōu)化網(wǎng)站內(nèi)鏈、網(wǎng)站設計公司網(wǎng)站設計

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設