189 8069 5689

java日历记事本源代码 java实现简单的日历功能

用Java编写简易记事本源代码

importjava.awt.BorderLayout;importjava.awt.Container;importjava.awt.Font;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListener;importjava.awt.event.InputEvent;importjava.awt.event.KeyAdapter;importjava.awt.event.KeyEvent;importjava.awt.event.MouseAdapter;importjava.awt.event.MouseEvent;importjava.awt.event.WindowAdapter;importjava.awt.event.WindowEvent;importjava.io.BufferedReader;importjava.io.BufferedWriter;importjava.io.File;importjava.io.FileReader;importjava.io.FileWriter;importjava.io.IOException;importjavax.swing.BorderFactory;importjavax.swing.JFileChooser;importjavax.swing.JFrame;importjavax.swing.JLabel;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;importjavax.swing.JOptionPane;importjavax.swing.JPopupMenu;importjavax.swing.JScrollPane;importjavax.swing.JTextArea;importjavax.swing.KeyStroke;importjavax.swing.ScrollPaneConstants;importjavax.swing.SwingConstants;publicclassJNotePadUIextendsJFrame{privateJMenuItemmenuOpen;privateJMenuItemmenuSave;privateJMenuItemmenuSaveAs;privateJMenuItemmenuClose;privateJMenueditMenu;privateJMenuItemmenuCut;privateJMenuItemmenuCopy;privateJMenuItemmenuPaste;privateJMenuItemmenuAbout;privateJTextAreatextArea;privateJLabelstateBar;privateJFileChooserfileChooser;privateJPopupMenupopUpMenu;publicJNotePadUI(){super("新建文本文件");setUpUIComponent();setUpEventListener();setVisible(true);}privatevoidsetUpUIComponent(){setSize(640,480);//菜单栏JMenuBarmenuBar=newJMenuBar();//设置「文件」菜单JMenufileMenu=newJMenu("文件");menuOpen=newJMenuItem("打开");//快捷键设置menuOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));menuSave=newJMenuItem("保存");menuSave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));menuSaveAs=newJMenuItem("另存为");menuClose=newJMenuItem("关闭");menuClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q,InputEvent.CTRL_MASK));fileMenu.add(menuOpen);fileMenu.addSeparator();//分隔线fileMenu.add(menuSave);fileMenu.add(menuSaveAs);fileMenu.addSeparator();//分隔线fileMenu.add(menuClose);//设置「编辑」菜单JMenueditMenu=newJMenu("编辑");menuCut=newJMenuItem("剪切");menuCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));menuCopy=newJMenuItem("复制");menuCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));menuPaste=newJMenuItem("粘贴");menuPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));editMenu.add(menuCut);editMenu.add(menuCopy);editMenu.add(menuPaste);//设置「关于」菜单JMenuaboutMenu=newJMenu("关于");menuAbout=newJMenuItem("关于JNotePad");aboutMenu.add(menuAbout);menuBar.add(fileMenu);menuBar.add(editMenu);menuBar.add(aboutMenu);setJMenuBar(menuBar);//文字编辑区域textArea=newJTextArea();textArea.setFont(newFont("宋体",Font.PLAIN,16));textArea.setLineWrap(true);JScrollPanepanel=newJScrollPane(textArea,ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);ContainercontentPane=getContentPane();contentPane.add(panel,BorderLayout.CENTER);//状态栏stateBar=newJLabel("未修改");stateBar.setHorizontalAlignment(SwingConstants.LEFT);stateBar.setBorder(BorderFactory.createEtchedBorder());contentPane.add(stateBar,BorderLayout.SOUTH);popUpMenu=editMenu.getPopupMenu();fileChooser=newJFileChooser();}privatevoidsetUpEventListener(){//按下窗口关闭钮事件处理addWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){closeFile();}});//菜单-打开menuOpen.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){openFile();}});//菜单-保存menuSave.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){saveFile();}});//菜单-另存为menuSaveAs.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){saveFileAs();}});//菜单-关闭文件menuClose.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){closeFile();}});//菜单-剪切menuCut.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){cut();}});//菜单-复制menuCopy.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){copy();}});//菜单-粘贴menuPaste.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){paste();}});//菜单-关于menuAbout.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){//显示对话框JOptionPane.showOptionDialog(null,"程序名称:\nJNotePad\n"+"程序设计:\n\n"+"简介:\n一个简单的文字编辑器\n"+"可作为验收Java的实现对象\n"+"欢迎网友下载研究交流\n\n"+"/","关于JNotePad",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}});//编辑区键盘事件textArea.addKeyListener(newKeyAdapter(){publicvoidkeyTyped(KeyEvente){processTextArea();}});//编辑区鼠标事件textArea.addMouseListener(newMouseAdapter(){publicvoidmouseReleased(MouseEvente){if(e.getButton()==MouseEvent.BUTTON3)popUpMenu.show(editMenu,e.getX(),e.getY());}publicvoidmouseClicked(MouseEvente){if(e.getButton()==MouseEvent.BUTTON1)popUpMenu.setVisible(false);}});}privatevoidopenFile(){if(isCurrentFileSaved()){//文件是否为保存状态open();//打开}else{//显示对话框intoption=JOptionPane.showConfirmDialog(null,"文件已修改,是否保存?","保存文件?",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE,null);switch(option){//确认文件保存caseJOptionPane.YES_OPTION:saveFile();//保存文件break;//放弃文件保存caseJOptionPane.NO_OPTION:open();break;}}}privatebooleanisCurrentFileSaved(){if(stateBar.getText().equals("未修改")){returnfalse;}else{returntrue;}}privatevoidopen(){//fileChooser是JFileChooser的实例//显示文件选取的对话框intoption=fileChooser.showDialog(null,null);//使用者按下确认键if(option==JFileChooser.APPROVE_OPTION){try{//开启选取的文件BufferedReaderbuf=newBufferedReader(newFileReader(fileChooser.getSelectedFile()));//设定文件标题setTitle(fileChooser.getSelectedFile().toString());//清除前一次文件textArea.setText("");//设定状态栏stateBar.setText("未修改");//取得系统相依的换行字符StringlineSeparator=System.getProperty("line.separator");//读取文件并附加至文字编辑区Stringtext;while((text=buf.readLine())!=null){textArea.append(text);textArea.append(lineSeparator);}buf.close();}catch(IOExceptione){JOptionPane.showMessageDialog(null,e.toString(),"开启文件失败",JOptionPane.ERROR_MESSAGE);}}}privatevoidsaveFile(){//从标题栏取得文件名称Filefile=newFile(getTitle());//若指定的文件不存在if(!file.exists()){//执行另存为saveFileAs();}else{try{//开启指定的文件BufferedWriterbuf=newBufferedWriter(newFileWriter(file));//将文字编辑区的文字写入文件buf.write(textArea.getText());buf.close();//设定状态栏为未修改stateBar.setText("未修改");}catch(IOExceptione){JOptionPane.showMessageDialog(null,e.toString(),"写入文件失败",JOptionPane.ERROR_MESSAGE);}}}privatevoidsaveFileAs(){//显示文件对话框intoption=fileChooser.showSaveDialog(null);//如果确认选取文件if(option==JFileChooser.APPROVE_OPTION){//取得选择的文件Filefile=fileChooser.getSelectedFile();//在标题栏上设定文件名称setTitle(file.toString());try{//建立文件file.createNewFile();//进行文件保存saveFile();}catch(IOExceptione){JOptionPane.showMessageDialog(null,e.toString(),"无法建立新文件",JOptionPane.ERROR_MESSAGE);}}}privatevoidcloseFile(){//是否已保存文件if(isCurrentFileSaved()){//释放窗口资源,而后关闭程序dispose();}else{intoption=JOptionPane.showConfirmDialog(null,"文件已修改,是否保存?","保存文件?",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE,null);switch(option){caseJOptionPane.YES_OPTION:saveFile();break;caseJOptionPane.NO_OPTION:dispose();}}}privatevoidcut(){textArea.cut();stateBar.setText("已修改");popUpMenu.setVisible(false);}privatevoidcopy(){textArea.copy();popUpMenu.setVisible(false);}privatevoidpaste(){textArea.paste();stateBar.setText("已修改");popUpMenu.setVisible(false);}privatevoidprocessTextArea(){stateBar.setText("已修改");}publicstaticvoidmain(String[]args){newJNotePadUI();}}

创新互联建站成立于2013年,是专业互联网技术服务公司,拥有项目成都做网站、网站制作网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元红岗做网站,已为上家服务,为红岗各地企业和个人服务,联系电话:18982081108

求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记事本源代码

给你个做好了的Java的源程序的记事本,自己看看就行了的,不怎么难的···

import java.awt.*;

import java.awt.event.*;

import java.io.*;

import javax.swing.*;

public class MyNotepad implements ActionListener{

private JFrame frame=new JFrame("新记事本");

private JTextArea jta=new JTextArea();

private String result="";

private boolean flag=true;

private File f;

private JButton jb=new JButton("开始");

private JTextField jtf=new JTextField(15);

private JTextField jt=new JTextField(15);

private JButton jbt=new JButton("替换为");

private JButton jba=new JButton("全部替换");

private Icon ic=new ImageIcon("D:\\java课堂笔记\\GUI\\11.gif");

private String value;

private int start=0;

private JFrame jf=new JFrame("查找");

private JFrame jfc=new JFrame("替换");

@Override

public void actionPerformed(ActionEvent e) {

String comm=e.getActionCommand();

if("新建".equals(comm)){

if(!(frame.getTitle().equals("新记事本"))){

if(!flag){

write();

newNew();

}else{

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

int returnVal = jfc.showDialog(null,"保存为");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

flag=false;

write();

}

}

}else if(!(jta.getText().isEmpty())){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

int returnVal = jfc.showDialog(null,"保存为");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

flag=false;

write();

newNew();

}

}else{

newNew();

}

}else if("打开".equals(comm)){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

jfc.setDialogType(JFileChooser.OPEN_DIALOG);

int returnVal = jfc.showOpenDialog(null);

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

frame.setTitle(f.getName());

result=read();

flag=false;

value=result;

jta.setText(result);

}

}else if("保存".equals(comm)){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

if(flag){

int returnVal = jfc.showDialog(null,"保存为");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

flag=false;

write();

}

}else{

write();

}

}else if("另存".equals(comm)){

JFileChooser jfc=new JFileChooser("D:\\java课堂笔记");

int returnVal = jfc.showDialog(null,"另存");

if(returnVal == JFileChooser.APPROVE_OPTION) {//选择文件后再执行下面的语句,保证了程序的健壮性

f=jfc.getSelectedFile();

write();

}

}else if("退出".equals(comm)){

System.exit(0);

}else if("撤销".equals(comm)){

jta.setText(value);

}else if("剪切".equals(comm)){

value=jta.getText();

jta.cut();

}else if("复制".equals(comm)){

jta.copy();

}else if("粘贴".equals(comm)){

value=jta.getText();

jta.paste();

}else if("删除".equals(comm)){

value=jta.getText();

jta.replaceSelection(null);

}else if("全选".equals(comm)){

jta.selectAll();

}else if("查找".equals(comm)){

value=jta.getText();

jf.add(jtf,BorderLayout.CENTER);

jf.add(jb,BorderLayout.SOUTH);

jf.setLocation(300,300);

jf.pack();

jf.setVisible(true);

jf.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}else if("替换".equals(comm)){

value=jta.getText();

GridLayout gl=new GridLayout(3,3);

JLabel jl1=new JLabel("查找内容:");

JLabel jl2=new JLabel("替换为:");

jfc.setLayout(gl);

jfc.add(jl1);

jfc.add(jtf);

jfc.add(jb);

jfc.add(jl2);

jfc.add(jt);

jfc.add(jbt);

JLabel jl3=new JLabel();

JLabel jl4=new JLabel();

jfc.add(jl3);

jfc.add(jl4);

jfc.add(jba);

jfc.setLocation(300,300);

jfc.pack();

jfc.setVisible(true);

jfc.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

}else if("版本".equals(comm)){

JDialog jd=new JDialog(frame,"关于对话框");

jd.setSize(200,200);

JLabel l=new JLabel("哈哈哈哈哈哈哈哈哈哈呵呵呵呵呵呵呵呵呵呵呵呵呵");

jd.add(l,BorderLayout.CENTER);

jd.setLocation(100,200);

jd.setSize(300,300);

jd.setVisible(true);

// jd.pack();

jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

}else if("开始".equals(comm)||"下一个".equals(comm)){

String temp=jtf.getText();

int s=value.indexOf(temp,start);

if(value.indexOf(temp,start)!=-1){

jta.setSelectionStart(s);

jta.setSelectionEnd(s+temp.length());

jta.setSelectedTextColor(Color.GREEN);

start=s+1;

jb.setText("下一个");

// value=value.substring(s+temp.length());//不能截取字串

}else {

JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);

jf.dispose();

}

}else if("替换为".equals(comm)){

String temp=jtf.getText();

int s=value.indexOf(temp,start);

if(value.indexOf(temp,start)!=-1){

jta.setSelectionStart(s);

jta.setSelectionEnd(s+temp.length());

jta.setSelectedTextColor(Color.GREEN);

start=s+1;

jta.replaceSelection(jt.getText());

}else {

JOptionPane.showMessageDialog(jf, "查找完毕!", "提示", 0, ic);

jf.dispose();

}

}else if("全部替换".equals(comm)){

String temp=jta.getText();

temp=temp.replaceAll(jtf.getText(), jt.getText());

jta.setText(temp);

}

}

public String read(){

String temp="";

try {

FileInputStream fis = new FileInputStream(f.getAbsolutePath());

byte[] b=new byte[1024];

while(true){

int num=fis.read(b);

if(num==-1)break;

temp=temp+new String(b,0,num);

}

fis.close();

} catch (Exception e1) {

e1.printStackTrace();

}

return temp;

}

public void write(){

try {

FileOutputStream fos=new FileOutputStream(f);

fos.write(jta.getText().getBytes());

fos.close();

} catch (Exception e) {

e.printStackTrace();

}

}

public void newNew(){

frame.dispose();

new MyNotepad();

flag=true;

}

public MyNotepad(){

JMenuBar jmb=new JMenuBar();

String[] menuLab={"文件","编辑","帮助"};

String[][] menuItemLab={{"新建","打开","保存","另存","退出"},

{"撤销","剪切","复制","粘贴","删除","全选","查找","替换"},

{"版本"}};

for(int i=0;imenuLab.length;i++){

JMenu menu=new JMenu(menuLab[i]);

jmb.add(menu);

for(int j=0;jmenuItemLab[i].length;j++){

JMenuItem jmi=new JMenuItem(menuItemLab[i][j]);

menu.add(jmi);

jmi.addActionListener(this);

}

}

frame.setJMenuBar(jmb);

jta.setLineWrap(true);//自动换行

JScrollPane jsp=new JScrollPane(jta);//滚动窗口面板

frame.add(jsp);

jb.addActionListener(this);

jbt.addActionListener(this);

jba.addActionListener(this);

frame.setLocation(200,50);

frame.setSize(620,660);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

public static void main(String[] args) {

new MyNotepad();

}

}

求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实现简单的日历功能
文章链接:http://jkwzsj.com/article/ddigojg.html

其他资讯