重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java小程序日历源代码 java设计日历小程序

关于Java的一个小程序,懂得来帮个忙

这是我编过的程序

十载的德令哈网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。营销型网站的优势是能够根据用户设备显示端的尺寸不同,自动调整德令哈建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。成都创新互联从事“德令哈网站设计”,“德令哈网站推广”以来,每个客户项目都认真落实执行。

它用来计算两个日期之间间隔

某日期向前/后几天是什么日期(考虑闰年)

星期几不好算,肯定要找个基准点

import java.awt.*;

import java.awt.event.*;

public class dakiler

{

public static void main(String args[])

{

new mainpage();

}

}

class mainpage extends Frame implements ActionListener

{

private Button button2,button3,button4;

forward frame1;

backward frame2;

twodates frame3;

mainpage()

{

super("主选择页面");

this.setLayout(new FlowLayout());

this.setLocation(250,250);

button2=new Button("日期向后计算");

button3=new Button("日期向前计算");

button4=new Button("两个日期计算");

button2.addActionListener(this);

button3.addActionListener(this);

button4.addActionListener(this);

this.add(button2);

this.add(button3);

this.add(button4);

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

this.pack();

this.show();

}

public void actionPerformed(ActionEvent e)

{

if(e.getSource()==button2)

{

this.setLocation(0,0);

forward frame1=new forward();

}

if(e.getSource()==button3)

{

this.setLocation(0,0);

backward frame2=new backward();

}

if(e.getSource()==button4)

{

this.setLocation(0,0);

twodates frame3=new twodates();

}

this.pack();

}

}

*/

class mainpage extends Frame implements ItemListener

{

private Choice choice;

private Label label1;

forward frame1;

backward frame2;

twodates frame3;

mainpage () {

this.setLayout(null);

this.setBounds(250,250,150,90);

choice=new Choice();

label1=new Label("请选择");

choice.addItem("日期向后计算");

choice.addItem("日期向前计算");

choice.addItem("两个日期计算");

choice.addItemListener(this);

label1.setBounds(20,30,100,20);

choice.setBounds(20,50,100,20);

this.add(label1);

this.add(choice);

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

this.show();

}

public void itemStateChanged(ItemEvent e)

{

if(choice.getSelectedItem().equals("日期向后计算"))

{

this.setLocation(0,0);

if (frame1!=null) frame1.dispose();

if (frame2!=null) frame2.dispose();

if (frame3!=null) frame3.dispose();

frame1=new forward();

}

if(choice.getSelectedItem().equals("日期向前计算"))

{

this.setLocation(0,0);

if (frame1!=null) frame1.dispose();

if (frame2!=null) frame2.dispose();

if (frame3!=null) frame3.dispose();

frame2=new backward();

}

if(choice.getSelectedItem().equals("两个日期计算"))

{

this.setLocation(0,0);

if (frame1!=null) frame1.dispose();

if (frame2!=null) frame2.dispose();

if (frame3!=null) frame3.dispose();

frame3=new twodates();

}

}

}

class forward extends Frame implements ActionListener

{

private Button button5,button6;

private TextField yeartextfield,monthtextfield,daytextfield,timetextfield,answertextfield;

private Label yearlabel,monthlabel,daylabel,timelabel,answerlabel;

private double year,month,day,time;

private boolean isren,iscontinue;

forward()

{

super("日期向后计算");

this.setLayout(null);

this.setBounds(0,250,800,150);

this.setResizable(false);

button5=new Button("确定");

button6=new Button("清除");

yearlabel=new Label("请输入年份");

monthlabel=new Label("请输入月份");

daylabel=new Label("请输入日期");

timelabel=new Label("请输入向后几天");

answerlabel=new Label("答案是");

yeartextfield=new TextField(5);

monthtextfield=new TextField(5);

daytextfield=new TextField(5);

timetextfield=new TextField(5);

answertextfield=new TextField(20);

button5.addActionListener(this);

button6.addActionListener(this);

yeartextfield.addActionListener(this);

monthtextfield.addActionListener(this);

daytextfield.addActionListener(this);

timetextfield.addActionListener(this);

yearlabel.setBounds(0,50,100,20);

yeartextfield.setBounds(100,50,100,20);

monthlabel.setBounds(0,80,100,20);

monthtextfield.setBounds(100,80,100,20);

daylabel.setBounds(0,110,100,20);

daytextfield.setBounds(100,110,100,20);

timelabel.setBounds(200,80,100,20);

timetextfield.setBounds(300,80,100,20);

button5.setBounds(400,80,100,20);

button6.setBounds(500,80,100,20);

answerlabel.setBounds(600,80,100,20);

answertextfield.setBounds(700,80,100,20);

this.add(yearlabel);

this.add(yeartextfield);

this.add(monthlabel);

this.add(monthtextfield);

this.add(daylabel);

this.add(daytextfield);

this.add(timelabel);

this.add(timetextfield);

this.add(button5);

this.add(button6);

this.add(answerlabel);

this.add(answertextfield);

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

dispose();

}

}

);

this.show();

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource()==button6)

{

yeartextfield.setText("");

monthtextfield.setText("");

daytextfield.setText("");

timetextfield.setText("");

answertextfield.setText("");

}

else if((e.getSource()==button5)||(e.getSource()==yeartextfield)||(e.getSource()==monthtextfield)||(e.getSource()==daytextfield)||(e.getSource()==timetextfield))

{

try

{

year=Double.parseDouble(yeartextfield.getText());

month=Double.parseDouble(monthtextfield.getText());

day=Double.parseDouble(daytextfield.getText());

time=Double.parseDouble(timetextfield.getText());

}

catch (Exception exc)

{

iscontinue=false;

answertextfield.setText("输入不正确");

}

function func=new function();

isren=func.ren(year);

iscontinue=false;

iscontinue=func.conti(month,day,isren);

if(iscontinue)

{

String str=func.plus(year,month,day,time);

answertextfield.setText(str);

}

else

{ answertextfield.setText("输入不正确");

}

}

}

}

class backward extends Frame implements ActionListener

{

private Button button5,button6;

private TextField yeartextfield,monthtextfield,daytextfield,timetextfield,answertextfield;

private Label yearlabel,monthlabel,daylabel,timelabel,answerlabel;

private double year,month,day,time;

private boolean isren,iscontinue;

backward()

{

super("日期向前计算");

this.setLayout(null);

this.setBounds(0,250,800,150);

this.setResizable(false);

button5=new Button("确定");

button6=new Button("清除");

yearlabel=new Label("请输入年份");

monthlabel=new Label("请输入月份");

daylabel=new Label("请输入日期");

timelabel=new Label("请输入向前几天");

answerlabel=new Label("答案是");

yeartextfield=new TextField(5);

monthtextfield=new TextField(5);

daytextfield=new TextField(5);

timetextfield=new TextField(5);

answertextfield=new TextField(20);

button5.addActionListener(this);

button6.addActionListener(this);

yeartextfield.addActionListener(this);

monthtextfield.addActionListener(this);

daytextfield.addActionListener(this);

timetextfield.addActionListener(this);

yearlabel.setBounds(0,50,100,20);

yeartextfield.setBounds(100,50,100,20);

monthlabel.setBounds(0,80,100,20);

monthtextfield.setBounds(100,80,100,20);

daylabel.setBounds(0,110,100,20);

daytextfield.setBounds(100,110,100,20);

timelabel.setBounds(200,80,100,20);

timetextfield.setBounds(300,80,100,20);

button5.setBounds(400,80,100,20);

button6.setBounds(500,80,100,20);

answerlabel.setBounds(600,80,100,20);

answertextfield.setBounds(700,80,100,20);

this.add(yearlabel);

this.add(yeartextfield);

this.add(monthlabel);

this.add(monthtextfield);

this.add(daylabel);

this.add(daytextfield);

this.add(timelabel);

this.add(timetextfield);

this.add(button5);

this.add(button6);

this.add(answerlabel);

this.add(answertextfield);

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

dispose();

}

}

);

this.show();

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource()==button6)

{

yeartextfield.setText("");

monthtextfield.setText("");

daytextfield.setText("");

timetextfield.setText("");

answertextfield.setText("");

}

else if((e.getSource()==button5)||(e.getSource()==yeartextfield)||(e.getSource()==monthtextfield)||(e.getSource()==daytextfield)||(e.getSource()==timetextfield))

{

try

{

year=Double.parseDouble(yeartextfield.getText());

month=Double.parseDouble(monthtextfield.getText());

day=Double.parseDouble(daytextfield.getText());

time=Double.parseDouble(timetextfield.getText());

}

catch (Exception exc)

{

iscontinue=false;

answertextfield.setText("输入不正确");

}

function func=new function();

isren=func.ren(year);

iscontinue=false;

iscontinue=func.conti(month,day,isren);

if(iscontinue)

{

String str=func.minus(year,month,day,time);

answertextfield.setText(str);

}

else

{ answertextfield.setText("输入不正确");

}

}

}

}

class twodates extends Frame implements ActionListener

{

private Button button5,button6;

private TextField yeartextfield1,monthtextfield1,daytextfield1,answertextfield,yeartextfield2,monthtextfield2,daytextfield2;

private Label yearlabel1,monthlabel1,daylabel1,yearlabel2,monthlabel2,daylabel2,answerlabel;

private double year1,month1,day1,year2,month2,day2;

private boolean isren1,isren2,iscontinue;

private int days;

public twodates()

{

super("两个日期计算");

this.setLayout(null);

this.setBounds(0,250,100,800);

this.setSize(800,150);

this.setResizable(false);

button5=new Button("确定");

button6=new Button("清除");

yearlabel1=new Label("请输入第一个年份");

monthlabel1=new Label("请输入第一个月份");

daylabel1=new Label("请输入第一个日期");

yearlabel2=new Label("请输入第二个年份");

monthlabel2=new Label("请输入第二个月份");

daylabel2=new Label("请输入第二个日期");

answerlabel=new Label("答案是");

yeartextfield1=new TextField(5);

monthtextfield1=new TextField(5);

daytextfield1=new TextField(5);

yeartextfield2=new TextField(5);

monthtextfield2=new TextField(5);

daytextfield2=new TextField(5);

answertextfield=new TextField(20);

button5.addActionListener(this);

button6.addActionListener(this);

yeartextfield1.addActionListener(this);

monthtextfield1.addActionListener(this);

daytextfield1.addActionListener(this);

yeartextfield2.addActionListener(this);

monthtextfield2.addActionListener(this);

daytextfield2.addActionListener(this);

yearlabel1.setBounds(0,50,100,20);

yeartextfield1.setBounds(100,50,100,20);

monthlabel1.setBounds(0,80,100,20);

monthtextfield1.setBounds(100,80,100,20);

daylabel1.setBounds(0,110,100,20);

daytextfield1.setBounds(100,110,100,20);

yearlabel2.setBounds(200,50,100,20);

yeartextfield2.setBounds(300,50,100,20);

monthlabel2.setBounds(200,80,100,20);

monthtextfield2.setBounds(300,80,100,20);

daylabel2.setBounds(200,110,100,20);

daytextfield2.setBounds(300,110,100,20);

button5.setBounds(400,80,100,20);

button6.setBounds(500,80,100,20);

answerlabel.setBounds(600,80,100,20);

answertextfield.setBounds(700,80,100,20);

this.add(yearlabel1);

this.add(yeartextfield1);

this.add(monthlabel1);

this.add(monthtextfield1);

this.add(daylabel1);

this.add(daytextfield1);

this.add(yearlabel2);

this.add(yeartextfield2);

this.add(monthlabel2);

this.add(monthtextfield2);

this.add(daylabel2);

this.add(daytextfield2);

this.add(button5);

this.add(button6);

this.add(answerlabel);

this.add(answertextfield);

this.addWindowListener(new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

dispose();

}

}

);

this.show();

}

public void actionPerformed(ActionEvent e)

{

if (e.getSource()==button6)

{

this.setSize(800,150);

yeartextfield1.setText("");

monthtextfield1.setText("");

daytextfield1.setText("");

yeartextfield2.setText("");

monthtextfield2.setText("");

daytextfield2.setText("");

answertextfield.setText("");

}

else if((e.getSource()==button5)||(e.getSource()==yeartextfield1)||(e.getSource()==monthtextfield1)||(e.getSource()==daytextfield1)||(e.getSource()==yeartextfield2)||(e.getSource()==monthtextfield2)||(e.getSource()==daytextfield2))

{

this.setSize(800,150);

try

{

year1=Double.parseDouble(yeartextfield1.getText());

month1=Double.parseDouble(monthtextfield1.getText());

day1=Double.parseDouble(daytextfield1.getText());

year2=Double.parseDouble(yeartextfield2.getText());

month2=Double.parseDouble(monthtextfield2.getText());

day2=Double.parseDouble(daytextfield2.getText());

}

catch (Exception exc)

{

iscontinue=false;

answertextfield.setText("输入不正确");

}

function func=new function();

isren1=func.ren(year1);

isren2=func.ren(year2);

iscontinue=false;

iscontinue=(func.conti(month1,day1,isren1))(func.conti(month2,day2,isren2));

if(iscontinue)

{

days=func.between(year1,month1,day1,year2,month2,day2);

answertextfield.setText("差"+days+"天");

}

else

{ answertextfield.setText("输入不正确");

}

}

}

}

class function

{

private String str;

private int year1,month1,day1,time1;

private int days=0;

private double temp;

public boolean ren(double year)

{

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

return true;

else return false;

}

public boolean conti(double month,double day,boolean isren)

{

boolean boo=true;

if((month=0)||(month12))

{ boo=false;}

else

{

switch ((int)month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12: if ((day31)||(day=0)) boo=false;

else boo=true;

break;

case 4:

case 6:

case 9:

case 11: if ((day30)||(day=0)) boo=false;

else boo=true;

break;

case 2: if (isren)

{

if ((day29)||(day=0)) boo=false;

else boo=true;

}

else

{

if ((day28)||(day=0)) boo=false;

else boo=true;

}

break;

}

}

return boo;

}

public String plus(double year,double month,double day,double time)

{

year1=(int)year;

month1=(int)month;

day1=(int)day;

time1=(int)time;

for (int i=1;i=time1;i++)

{

if ((month1==12)(day1==31))

{

year1++;

month1=1;

day1=1;

}

else if (((month1==1)||(month1==3)||(month1==5)||(month1==7)||(month1==8)||(month1==10))(day1==31))

{

month1++;

day1=1;

}

else if(((month1==4)||(month1==6)||(month1==9)||(month1==11))(day1==30))

{

求Java 日历的小程序的源代码

也不知道你具体需求是什么,以前改过一个日历程序,一共四个java类,放在同一个包里。经测试可以运行。

//Start.java

import java.awt.*;

import javax.swing.*;

class Start{

public static void main(String [] args){

DateFrame frame=new DateFrame();

frame.setLocationRelativeTo(frame);

frame.setResizable(false);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

}

}

//DateInfo.java

import java.util.*;

public class DateInfo{

private int mYear, mMonth;

private int mDayOfMonth, mFristWeek;

public DateInfo(int year, int month) throws DateException{

mYear = year;

if (month 0 || month 12){

throw (new DateException());

}

mMonth = month;

mDayOfMonth = getDayOfMonth(mYear, mMonth);

mFristWeek = getFristWeek(mYear, mMonth);

}

private int getDayOfMonth(int year, int month){

int[][] ary = {{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},

{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};

return (ary[isLeapYear(year)][month]);

}

private int isLeapYear(int year){

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

return (1);

}

else{

return (0);

}

}

private int getFristWeek(int year, int month){

java.util.Calendar cal = Calendar.getInstance();

cal.set(year, month - 1, 1);

return (cal.get(Calendar.DAY_OF_WEEK) - 1);

}

public String toString(){

String str;

str = "\t\t" + mYear + "年" + mMonth + "月\n";

str += "日\t一\t二\t三\t四\t五\t六\n";

int i;

for (i = 1; i = mFristWeek; i++){

str += " \t";

}

for (int j = 1; j = mDayOfMonth; j++, i++){

str +=j+"\t" ;

if (i % 7 == 0){

str += "\n";

}

}

return (str);

}

}

//DateFrame.java

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import java.util.Calendar;

class DateFrame extends JFrame implements Runnable{

Calendar date=Calendar.getInstance();

String[] str={"1","2","3","4","5","6","7","8","9","10","11","12"};

JLabel lblYear=new JLabel("年 ");

JLabel lblMonth=new JLabel("月 ");

JLabel lblDate=new JLabel("现在的时间是:");

JLabel lblShowDate=new JLabel();

// javax.swing.JTextField trxt =new JTextField(10);

// trxt.setHorizontalAlignment(JTextField.RIGHT); //设置文本从右边输入

JComboBox cboMonth=new JComboBox(str);

JComboBox cboYear=new JComboBox();

JTextArea txaShow=new JTextArea();

JPanel pnlNorth=new JPanel();

JPanel pnlSOUTH=new JPanel();

JButton btnShow=new JButton("显示");

JButton btnClose=new JButton("关闭");

JScrollPane jsp=new JScrollPane(txaShow);

Container c=this.getContentPane();

public DateFrame(){

Thread thread=new Thread(this);

thread.start();

this.setTitle("玩玩日历拉!!!");

this.setSize(300,260);

for (int i = 1990; i=2025; i++) {

cboYear.addItem(""+i);

}

cboYear.setSelectedItem(""+(date.get(Calendar.YEAR)));

cboMonth.setSelectedItem(""+(date.get(Calendar.MONTH)+1));

pnlNorth.add(cboYear);

txaShow.setTabSize(4); //设置tab键的距离

txaShow.setForeground(Color.GREEN);

pnlNorth.add(lblYear);

pnlNorth.add(cboMonth);

pnlNorth.add(lblMonth);

pnlNorth.add(lblDate);

pnlNorth.add(lblShowDate);

c.add(pnlNorth,BorderLayout.NORTH);

c.add(jsp);

pnlSOUTH.add(btnShow);

pnlSOUTH.add(btnClose);

c.add(pnlSOUTH,BorderLayout.SOUTH);

btnShow.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

int year=Integer.parseInt((String)cboYear.getSelectedItem());

int month=Integer.parseInt((String)cboMonth.getSelectedItem());

try {

DateInfo date=new DateInfo(year,month);

txaShow.setText(""+date);

}

catch (DateException ex) {

ex.printStackTrace();

}

}

});

btnClose.addActionListener(new ActionListener(){

public void actionPerformed(ActionEvent e){

System.exit(0);

}

});

}

public void run(){

try {

while(true){

Thread.sleep(1000);

int hour=date.get(Calendar.HOUR);

int minute=date.get(Calendar.MINUTE);

int second=date.get(Calendar.SECOND);

String str=hour+":"+minute+":"+second;

lblShowDate.setText(str);

//this.repaint();

}

}

catch (Exception ex) {

ex.printStackTrace();

}

}

}

//DateException.java

public class DateException extends Exception{

public DateException(){

super("日期数据不合法.");

}

}

求Java万年历源代码!!!

我有个JS的要么?

你可以把他改下我是没时间帮你该哈!!!

!--日期框选择--

var DS_x,DS_y;

function dateSelector() //构造dateSelector对象,用来实现一个日历形式的日期输入框。

{

var myDate=new Date();

this.year=myDate.getFullYear(); //定义year属性,年份,默认值为当前系统年份。

this.month=myDate.getMonth()+1; //定义month属性,月份,默认值为当前系统月份。

this.date=myDate.getDate(); //定义date属性,日,默认值为当前系统的日。

this.inputName=''; //定义inputName属性,即输入框的name,默认值为空。注意:在同一页中出现多个日期输入框,不能有重复的name!

this.display=display; //定义display方法,用来显示日期输入框。

}

function display() //定义dateSelector的display方法,它将实现一个日历形式的日期选择框。

{

var week=new Array('日','一','二','三','四','五','六');

document.write("style type=text/css");

document.write(" .ds_font td,span { font: normal 12px 宋体; color: #000000; }");

document.write(" .ds_border { border: 1px solid #000000; cursor: hand; background-color: #DDDDDD }");

document.write(" .ds_border2 { border: 1px solid #000000; cursor: hand; background-color: #DDDDDD }");

document.write("/style");

var M=new String(this.month);

var d=new String(this.date);

if(M.length==1d.length==1){

document.write("input style='text-align:center;' id='DS_"+this.inputName+"' name='"+this.inputName+"' value='"+this.year+"-0"+this.month+"-0"+this.date+"' title=双击可进行编缉 ondblclick='this.readOnly=false;this.focus()' onblur='this.readOnly=true' readonly");}

else if(M.length==1d.length==2){

document.write("input style='text-align:center;' id='DS_"+this.inputName+"' name='"+this.inputName+"' value='"+this.year+"-0"+this.month+"-"+this.date+"' title=双击可进行编缉 ondblclick='this.readOnly=false;this.focus()' onblur='this.readOnly=true' readonly");}

else if(M.length==2d.length==1){

document.write("input style='text-align:center;' id='DS_"+this.inputName+"' name='"+this.inputName+"' value='"+this.year+"-"+this.month+"-0"+this.date+"' title=双击可进行编缉 ondblclick='this.readOnly=false;this.focus()' onblur='this.readOnly=true' readonly");}

else if(M.length==2d.length==2){

document.write("input style='text-align:center;' id='DS_"+this.inputName+"' name='"+this.inputName+"' value='"+this.year+"-"+this.month+"-"+this.date+"' title=双击可进行编缉 ondblclick='this.readOnly=false;this.focus()' onblur='this.readOnly=true' readonly");}

document.write("button style='width:60px;height:18px;font-size:12px;margin:1px;border:1px solid #A4B3C8;background-color:#DFE7EF;' type=button onclick=this.nextSibling.style.display='block' onfocus=this.blur()日期/button");

document.write("div style='position:absolute;display:none;text-align:center;width:0px;height:0px;overflow:visible' onselectstart='return false;'");

document.write(" div style='position:absolute;left:-60px;top:20px;width:142px;height:165px;background-color:#F6F6F6;border:1px solid #245B7D;' class=ds_font");

document.write(" table cellpadding=0 cellspacing=1 width=140 height=20 bgcolor=#CEDAE7 onmousedown='DS_x=event.x-parentNode.style.pixelLeft;DS_y=event.y-parentNode.style.pixelTop;setCapture();' onmouseup='releaseCapture();' onmousemove='dsMove(this.parentNode)' style='cursor:move;'");

document.write(" tr align=center");

document.write(" td width=12% onmouseover=this.className='ds_border' onmouseout=this.className='' onclick=subYear(this) title='减小年份'/td");

document.write(" td width=12% onmouseover=this.className='ds_border' onmouseout=this.className='' onclick=subMonth(this) title='减小月份'/td");

document.write(" td width=52%b"+this.year+"/bb年/bb"+this.month+"/bb月/b/td");

document.write(" td width=12% onmouseover=this.className='ds_border' onmouseout=this.className='' onclick=addMonth(this) title='增加月份'/td");

document.write(" td width=12% onmouseover=this.className='ds_border' onmouseout=this.className='' onclick=addYear(this) title='增加年份'/td");

document.write(" /tr");

document.write(" /table");

document.write(" table cellpadding=0 cellspacing=0 width=140 height=20 onmousedown='DS_x=event.x-parentNode.style.pixelLeft;DS_y=event.y-parentNode.style.pixelTop;setCapture();' onmouseup='releaseCapture();' onmousemove='dsMove(this.parentNode)' style='cursor:move;'");

document.write(" tr align=center");

for(i=0;i7;i++)

document.write(" td"+week[i]+"/td");

document.write(" /tr");

document.write(" /table");

document.write(" table cellpadding=0 cellspacing=2 width=140 bgcolor=#EEEEEE");

for(i=0;i6;i++)

{

document.write(" tr align=center");

for(j=0;j7;j++)

document.write(" td width=10% height=16 onmouseover=if(this.innerText!=''this.className!='ds_border2')this.className='ds_border' onmouseout=if(this.className!='ds_border2')this.className='' onclick=getValue(this,document.all('DS_"+this.inputName+"'))/td");

document.write(" /tr");

}

document.write(" /table");

document.write(" span style=cursor:hand onclick=this.parentNode.parentNode.style.display='none'【关闭】/span");

document.write(" /div");

document.write("/div");

dateShow(document.all("DS_"+this.inputName).nextSibling.nextSibling.childNodes[0].childNodes[2],this.year,this.month)

}

function subYear(obj) //减小年份

{

var myObj=obj.parentNode.parentNode.parentNode.cells[2].childNodes;

myObj[0].innerHTML=eval(myObj[0].innerHTML)-1;

dateShow(obj.parentNode.parentNode.parentNode.nextSibling.nextSibling,eval(myObj[0].innerHTML),eval(myObj[2].innerHTML))

}

function addYear(obj) //增加年份

{

var myObj=obj.parentNode.parentNode.parentNode.cells[2].childNodes;

myObj[0].innerHTML=eval(myObj[0].innerHTML)+1;

dateShow(obj.parentNode.parentNode.parentNode.nextSibling.nextSibling,eval(myObj[0].innerHTML),eval(myObj[2].innerHTML))

}

function subMonth(obj) //减小月份

{

var myObj=obj.parentNode.parentNode.parentNode.cells[2].childNodes;

var month=eval(myObj[2].innerHTML)-1;

if(month==0)

{

month=12;

subYear(obj);

}

myObj[2].innerHTML=month;

dateShow(obj.parentNode.parentNode.parentNode.nextSibling.nextSibling,eval(myObj[0].innerHTML),eval(myObj[2].innerHTML))

}

function addMonth(obj) //增加月份

{

var myObj=obj.parentNode.parentNode.parentNode.cells[2].childNodes;

var month=eval(myObj[2].innerHTML)+1;

if(month==13)

{

month=1;

addYear(obj);

}

myObj[2].innerHTML=month;

dateShow(obj.parentNode.parentNode.parentNode.nextSibling.nextSibling,eval(myObj[0].innerHTML),eval(myObj[2].innerHTML))

}

function dateShow(obj,year,month) //显示各月份的日

{

var myDate=new Date(year,month-1,1);

var today=new Date();

var day=myDate.getDay();

var selectDate=obj.parentNode.parentNode.previousSibling.previousSibling.value.split('-');

var length;

switch(month)

{

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

length=31;

break;

case 4:

case 6:

case 9:

case 11:

length=30;

break;

case 2:

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

length=29;

else

length=28;

}

for(i=0;iobj.cells.length;i++)

{

obj.cells[i].innerHTML='';

obj.cells[i].style.color='';

obj.cells[i].className='';

}

for(i=0;ilength;i++)

{

obj.cells[i+day].innerHTML=(i+1);

if(year==today.getFullYear()(month-1)==today.getMonth()(i+1)==today.getDate())

obj.cells[i+day].style.color='red';

if(year==eval(selectDate[0])month==eval(selectDate[1])(i+1)==eval(selectDate[2]))

obj.cells[i+day].className='ds_border2';

}

}

function getValue(obj,inputObj) //把选择的日期传给输入框

{

var myObj=inputObj.nextSibling.nextSibling.childNodes[0].childNodes[0].cells[2].childNodes;

if(obj.innerHTML)

if(obj.innerHTML.length==1myObj[2].innerHTML.length==1)

inputObj.value=myObj[0].innerHTML+"-0"+myObj[2].innerHTML+"-0"+obj.innerHTML;

else if(obj.innerHTML.length==1myObj[2].innerHTML.length==2)

inputObj.value=myObj[0].innerHTML+"-"+myObj[2].innerHTML+"-0"+obj.innerHTML;

else if(obj.innerHTML.length==2myObj[2].innerHTML.length==1)

inputObj.value=myObj[0].innerHTML+"-0"+myObj[2].innerHTML+"-"+obj.innerHTML;

else if(obj.innerHTML.length==2myObj[2].innerHTML.length==2)

inputObj.value=myObj[0].innerHTML+"-"+myObj[2].innerHTML+"-"+obj.innerHTML;

inputObj.nextSibling.nextSibling.style.display='none';

for(i=0;iobj.parentNode.parentNode.parentNode.cells.length;i++)

obj.parentNode.parentNode.parentNode.cells[i].className='';

obj.className='ds_border2'

}

function dsMove(obj) //实现层的拖移

{

if(event.button==1)

{

var X=obj.clientLeft;

var Y=obj.clientTop;

obj.style.pixelLeft=X+(event.x-DS_x);

obj.style.pixelTop=Y+(event.y-DS_y);

}

}

/***调用代码**

script language=javascript

var myDate=new dateSelector();

myDate.year=1900;//morenqiri

myDate.inputName='date'; //

myDate.display();

/script

*/


网页标题:java小程序日历源代码 java设计日历小程序
URL分享:http://cqcxhl.com/article/doopsjg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP