精华内容
下载资源
问答
  • java 自制日历
    2019-05-30 15:18:14
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;
    import java.util.Date;
    import java.util.GregorianCalendar;
    import java.util.Scanner;
    
    public class TestCalenderClass2 {
    	public static void main(String[] args) throws ParseException {
    		System.out.println("请输入日期(例如2018-10-10):");//输入日期
    		Scanner input = new Scanner(System.in);//建立输入对象
    		String date = input.nextLine();//获得输入日期的字符串
    		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    		Date d = df.parse(date);//转换成时间对象
    		Calendar c = new GregorianCalendar();//建立日历对象
    		c.setTime(d);//设置日历的时间
    		
    		int day = c.get(Calendar.DAY_OF_MONTH);//输入的日期为本月第几天
    		System.out.println("日\t"+"一\t"+"二\t"+"三\t"+"四\t"+"五\t"+"六\t");
    		
    		c.set(Calendar.DAY_OF_MONTH, 1);//设置本月一号
    		int maxday = c.getActualMaximum(Calendar.DATE);//获取本月的最大天数
    		for (int i = 0; i < c.get(Calendar.DAY_OF_WEEK) - 1; i++) {
    			System.out.print("\t");
    		}
    		
    		for (int i = 1; i <= maxday; i++) {//遍历本月所有的日子
    			if(day == i) {//如果是输入的天数 则在天数旁边加上*号
    				System.out.print(c.get(Calendar.DAY_OF_MONTH) + "*\t");
    			}else {
    				System.out.print(c.get(Calendar.DAY_OF_MONTH) + "\t");
    			}
    			
    			if(c.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY) {//如果是周六则换行
    				System.out.println();
    			}
    			c.add(Calendar.DAY_OF_MONTH, 1);//日期加一
    		}
    		
    	}
    }
    

     

     

    请输入日期(例如2018-10-10):
    2019-09-09
    日	一	二	三	四	五	六	
    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	

     

    更多相关内容
  • 本文我们要利用无字库12864液晶模块来自制一个小小日历钟,图终效果图见图1。  这个小小日历钟有什么特点呢?  1、电路简单,使用元件少,容易制作,就是单片机ATMega8L和日历钟忡1302。  2、全部使用低压...
  • 自制日历农历

    2018-09-20 17:04:42
    支持农历、名各种节假日、黄历等。
  • 本文我们要利用无字库12864液晶模块来自制一个小小日历钟,最图终效果图见图1。  这个小小日历钟有什么特点呢?  1、电路简单,使用元件少,容易制作,核心就是单片机ATMega8L和日历钟忡1302。  2、全部使用...
  • 设置日历年份范围,日历上面显示每天todo list,点击某天,显示当天每个todo事件的发生时间段
  • 自定义精美日历的备忘录,用Visual Studio 2012-C#开发,数据库是Microsoft SQL Server 2012。压缩包里面有源代码,数据库以及说明文档。
  • Jquery-calendar 自制日历控件
  • 自制日历java

    2021-12-16 13:46:12
    没有事情做随便写了一个日历,用java语言
    package pac02;
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import java.io.*;
    import java.time.DayOfWeek;
    import java.time.LocalDate;
    import java.time.LocalDateTime;
    import java.time.Month;
    import java.util.Iterator;
    import java.util.LinkedList;
    
    public class MyCourseDesign {
        public static void main(String[] args) {
            new InitWindow();
        }
    }
    
    class MyTable implements ActionListener{        //view
        JButton button;         //按钮确定输入
        JButton nextMonth;
        JButton previousMonth;
        JButton TableBack;
        JTextField inputYear;   //输入年份
        JComboBox<String>inputmonth; //下拉框选择月份
        MyPolice police;        //确定按钮的监视器
        JLabel  yearLabel;      //提示年的标签
        JLabel monthLabel;      //提示月的标签
        JLabel NowLabel;
        JButton nowButton;
        MyCalnadar myCalnadar;    //显示日历的主体
        JPanel northPanel;
        JPanel centralPanel;
        JPanel southPanel;
        JLayeredPane layeredPane;
        JPanel allPanel;
        LocalDateTime timeNow;
        Timer time;
        Box panelBox;
        InitWindow win;
    
        MyTable(){
            init();
            allPanel.setVisible(true);
            allPanel.setBounds(200,200,700,500);
        }
    
        public void setMyFont(Font font,JComponent...x){
            for(JComponent c:x){
                c.setFont(font);
            }
        }
    
        public void init(){
            BorderLayout bord = new BorderLayout();
            allPanel = new JPanel();
            allPanel.setLayout(bord);
            TableBack = new JButton("返回");
            panelBox = Box.createVerticalBox();
            nextMonth = new JButton(">>");
            previousMonth = new JButton("<<");
            myCalnadar = new MyCalnadar();
            police = new MyPolice();
            time = new Timer(1000,this);
            time.start();
            button  =new JButton("显示");
            inputmonth = new JComboBox<>();
            inputYear = new JTextField(6);
            yearLabel  = new JLabel("输入年:");
            monthLabel  = new JLabel("请选择月:");
            northPanel = new JPanel();
            centralPanel = new JPanel();
            southPanel = new JPanel();
            allPanel = new JPanel();
            layeredPane = new JLayeredPane();
            String []s1=new String[12];
            timeNow = LocalDateTime.now();
            NowLabel = new JLabel("现在的时间:"+timeNow.getYear()+"年"+timeNow.getMonth()+"月"+timeNow.getDayOfMonth()+"日"+timeNow.getHour()+":"+timeNow.getMinute()+":"+timeNow.getSecond());
            for (int i = 1; i <= 12; i++) {
                s1[i-1] = new String(String.valueOf(i));
                inputmonth.addItem(s1[i-1]);
            }
            setWin(win);
            police.setView(this);
            myCalnadar.setView(this);
            myCalnadar.setPanel(centralPanel);
            button.addActionListener(police);
            Font font = new Font("宋体",Font.BOLD,20);
            Font font01 = new Font("楷体",Font.BOLD,30);
            setMyFont(font,yearLabel,monthLabel,inputYear,inputmonth,button,nextMonth,previousMonth,NowLabel,button,TableBack);
            northPanel.add(TableBack);
            northPanel.add(yearLabel);
            northPanel.add(inputYear);
            northPanel.add(monthLabel);
            northPanel.add(inputmonth);
            northPanel.add(button);
            northPanel.add(previousMonth);
            northPanel.add(nextMonth);
    
            TableBack.addActionListener(police);
    
            previousMonth.addActionListener(police);
            nextMonth.addActionListener(police);
            nowButton= new JButton("");
            nowButton.setFont(font01);
            panelBox.add(nowButton);
            panelBox.add(Box.createVerticalStrut(4));
            panelBox.add(NowLabel);
            southPanel.add(panelBox);
            allPanel.add(northPanel,BorderLayout.NORTH);
            allPanel.add(centralPanel,BorderLayout.CENTER);
            allPanel.add(southPanel,BorderLayout.SOUTH);
    
            //初始时使日历显示2021年1月的日历
            inputYear.setText(2021+"");
            myCalnadar.setYear(2021);
            myCalnadar.setMonth(1);
            myCalnadar.showCalnadar();
            nowButton.setText("2021年1月日历");
        }
    
        public void actionPerformed(ActionEvent ae){
            //实现计时器功能
            time.start();
            LocalDateTime timeNow = LocalDateTime.now();
            NowLabel.setText("现在的时间:"+timeNow.getYear()+"年"+police.Convers(timeNow.getMonth())+"月"+timeNow.getDayOfMonth()+"日"+timeNow.getHour()+":"+timeNow.getMinute()+":"+timeNow.getSecond());
        }
    
        public void setWin(InitWindow win){
            this.win = win;
        }
    
        public void setPanel(JPanel panel){
            this.allPanel=panel;
        }
    
    }
    
    class MyCalnadar{               //Module
        int year;
        int month;
        GridLayout grid;
        JPanel panel;
        MyTable view;
        public void setView(MyTable view){
            this.view=view;
        }
    
        public void setPanel(JPanel panel){
            this.panel = panel;
        }
    
        public void setYear(int year) {
            this.year = year;
        }
    
        public void setMonth(int month) {
            this.month = month;
        }
    
        public int getYear() {
            return year;
        }
    
        public int getMonth() {
            return month;
        }
    
        public int PrintSpace(DayOfWeek x){
            switch (x){
                case MONDAY -> {
                    return 0;
                }
                case TUESDAY -> {
                    return 1;
                }
                case WEDNESDAY -> {
                    return 2;
                }
                case THURSDAY -> {
                    return 3;
                }
                case FRIDAY -> {
                    return 4;
                }
                case SATURDAY -> {
                    return 5;
                }
                case SUNDAY -> {
                    return 6;
                }
                default -> {
                    return -1;
                }
            }
        }
    
        public void showCalnadar(){
            Font font02 = new Font("楷体",Font.PLAIN,30);
            panel.setFont(font02);
            panel.setSize(100,100);
            Font font01 = new Font("宋体",Font.BOLD,20);
            panel.removeAll();
            grid = new GridLayout(7,7);
            panel.setLayout(grid);
            LocalDate date = LocalDate.of(year,month,1);
            int days = date.lengthOfMonth();
            LocalDate[]dateArray = new LocalDate[days];
            for (int i = 0; i < days; i++) {
                dateArray[i] =LocalDate.of(year,month,date.getDayOfMonth()+i);
            }
            String []name = new String[]{"Mon","Tue","Wed","Thu","Fri","Sat","Sun"};
            //发现显示不了中文
            Label []titleWeek= new Label[7];
            Label []showDay = new Label[42];
            for(int i=0;i<7;i++){
                titleWeek[i] = new Label("",Label.CENTER);
                titleWeek[i].setText(name[i]+"");
                titleWeek[i].setFont(font01);
                panel.add(titleWeek[i]);
            }
            for(int i=0;i<42;i++){
                showDay[i] = new Label("",Label.CENTER);
                panel.add(showDay[i]);
            }
            int spaceOfMonth = PrintSpace(dateArray[0].getDayOfWeek());
            for (int i = 0; i < spaceOfMonth; i++) {
                showDay[i].setText("");
            }
            for (int i = spaceOfMonth,j=0; j < days; j++,i++) {
                showDay[i].setText(""+dateArray[j].getDayOfMonth());
            }
            panel.repaint();
        }
    }
    
    class MyPolice implements ActionListener {     //Controller
        MyTable view;
        int year,month;
        boolean isShow=true;
        boolean canEdit = true;
        Font font = new Font("宋体",Font.BOLD,17);
        public void setView(MyTable view){
            this.view=view;
        }
        public void actionPerformed(ActionEvent ae){
            if(ae.getSource()== view.TableBack){
                view.win.card.show(view.win.allPanel,"firstPanel");
            }
            if(ae.getSource()==view.button){
                //显示日历的主体
                if(view.inputYear.getText()==null){
                    //如果根本没有输入年份
                    canEdit = false;
                    JLabel label1 = new JLabel("请输入年份!!!");
                    label1.setFont(font);
                    label1.setBackground(Color.RED);
                    JOptionPane.showMessageDialog(view.allPanel,label1,"提示输入提醒",JOptionPane.ERROR_MESSAGE);
                }
                else{
                    canEdit = true;
                }
                try{
                    //尝试看看输入的年份有没有其他字符
                    year = Integer.parseInt(view.inputYear.getText());
                    canEdit = true;
                }
                catch (NumberFormatException exp){
                    canEdit = false;
                    JLabel label1 = new JLabel("输入的年份不要包含除数字之外的其他格式!!!");
                    label1.setFont(font);
                    view.inputYear.setText(2021+"");
                    label1.setForeground(Color.RED);
                    JOptionPane.showMessageDialog(view.allPanel,label1,"输入格式提醒",JOptionPane.ERROR_MESSAGE);
                    isShow=false;
                    view.inputYear.requestFocus();
                }
                if(view.inputYear.getText()!=null&&(year>3500||year<1500)){
                    //检查输入的年份有没有超出范围
                    canEdit = false;
                    JLabel label1 = new JLabel("年份超出范围!请在1500-3500之间输入");
                    label1.setFont(font);
                    view.inputYear.setText("2021");
                    label1.setForeground(Color.RED);
                    JOptionPane.showMessageDialog(view.allPanel,label1,"超出范围提醒",JOptionPane.ERROR_MESSAGE);
                    isShow=false;
    //                view.inputYear.setText(null);
                    view.inputYear.requestFocus();
                }
                else{
                    canEdit = true;
                }
                try{
                    //操作选中的月份
                    int month = Integer.parseInt(view.inputmonth.getSelectedItem().toString());
                    canEdit = true;
                }
                catch (Exception exp){
                    canEdit = false;
                    JLabel label1 = new JLabel("您还未选择月份!!!");
                    label1.setFont(font);
                    label1.setForeground(Color.RED);
                    JOptionPane.showMessageDialog(view.allPanel,label1,"提示选择提醒",JOptionPane.ERROR_MESSAGE);
                    isShow=false;
                }
                //根据输入的数据显示日历
                int year = Integer.parseInt(view.inputYear.getText());
                int month = Integer.parseInt(view.inputmonth.getSelectedItem().toString());
                view.myCalnadar.setYear(year);
                view.myCalnadar.setMonth(month);
            }
            if(ae.getSource()==view.nextMonth){
                //按按钮以显示下一个月的日历
                if(canEdit){
                    int year = view.myCalnadar.getYear();
                    int month = view.myCalnadar.getMonth();
                    if(month==12){
                        view.myCalnadar.setYear(year+1);
                        view.myCalnadar.setMonth(1);
                    }
                    else{
                        view.myCalnadar.setMonth(month+1);
                    }
                }
                else{
                    JLabel label1 = new JLabel("请先显示日历后再按按钮挑战月份!");
                    label1.setFont(font);
                    label1.setForeground(Color.RED);
                    JOptionPane.showMessageDialog(view.allPanel,label1,"错误选择提醒",JOptionPane.ERROR_MESSAGE);
                }
            }
            if(ae.getSource()== view.previousMonth){
                //按按钮以显示上一个月的日历
                if(canEdit){
                    int year = view.myCalnadar.getYear();
                    int month = view.myCalnadar.getMonth();
                    if(month==1){
                        view.myCalnadar.setYear(year-1);
                        view.myCalnadar.setMonth(12);
                    }
                    else{
                        view.myCalnadar.setMonth(month-1);
                    }
                }
                else {
                    JLabel label1 = new JLabel("请先显示日历后再按按钮挑战月份!");
                    label1.setFont(font);
                    label1.setForeground(Color.RED);
                    JOptionPane.showMessageDialog(view.allPanel,label1,"错误选择提醒",JOptionPane.ERROR_MESSAGE);
                }
            }
            if(isShow&canEdit){
                //根据有没有错误数据来显示日历主体
                view.myCalnadar.showCalnadar();
                view.nowButton.setText(view.myCalnadar.getYear()+"年"+ view.myCalnadar.getMonth()+"月的日历");
                view.nowButton.setBackground(Color.WHITE);
            }
            isShow=true;
        }
        public int Convers(Month m){
            switch (m){
                case JANUARY -> {
                    return 1;
                }
                case FEBRUARY -> {
                    return 2;
                }
                case MARCH -> {
                    return 3;
                }
                case APRIL -> {
                    return 4;
                }
                case MAY -> {
                    return 5;
                }
                case JUNE -> {
                    return 6;
                }
                case JULY -> {
                    return 7;
                }
                case AUGUST -> {
                    return 8;
                }
                case SEPTEMBER -> {
                    return 9;
                }
                case OCTOBER -> {
                    return 10;
                }
                case NOVEMBER -> {
                    return 11;
                }
                case DECEMBER -> {
                    return 12;
                }
                default -> {
                    return -1;
                }
            }
        }
    }
    
    class InitWindow extends JFrame implements ActionListener{
        JButton showCal;
        JButton showMes;
        JButton showOpe;
        JPanel CalPanel;
        JPanel MesPanel;
        JPanel OpePanel;
        JLabel imageLabel;
        JPanel imagePanel;
        JPanel allPanel;
        JPanel firstPanel;
        JLayeredPane layeredPane;
        ImageIcon icon;
        Box baseBox;
        Box box1;
        Box box2;
        Font font,font01;
        JLabel hiLabel;
        JLabel opeLabel;
        JLabel spaceLabel;
        JLabel imaLabel;
        CardLayout card;
        MessageWindow mesWin;
        MyTable tabWin;
        OperateWindow opeWin;
    
        InitWindow(){
            init();
            setBounds(200,200,700,500);
            setVisible(true);
            setTitle("自制多功能日历器");
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        }
        public void init(){
            mesWin = new MessageWindow();
            mesWin.setView(this);
            tabWin = new MyTable();
            tabWin.setWin(this);
            opeWin = new OperateWindow();
            opeWin.setView((this));
            card = new CardLayout();
            CalPanel = new JPanel();
            OpePanel = new JPanel();
            MesPanel = new JPanel();
            allPanel = new JPanel();
            firstPanel = new JPanel();
            allPanel.setLayout(card);
            allPanel.add("OpePanel",opeWin.allPanel);
            allPanel.add("MesPanel",mesWin.allPanel);
            allPanel.add("CalPanel",tabWin.allPanel);
            allPanel.add("firstPanel",firstPanel);
            //对应3个窗口
            showCal = new JButton("查看日历");
            showMes = new JButton("查看节日");
            showOpe = new JButton("查看日程");
            showOpe.addActionListener(this);
            showMes.addActionListener(this);
            showCal.addActionListener(this);
    
            font = new Font("微软雅黑",Font.ITALIC,20);
            font01 = new Font("宋体",Font.PLAIN,50);
            hiLabel = new JLabel("你好,Calendar");
    //        imagePanel.setSize(icon.getIconWidth(),icon.getIconHeight());
    //        imagePanel.add(imageLabel,BorderLayout.CENTER);
    
            setBox();
    
    //        layeredPane.add(imagePanel,JLayeredPane.MODAL_LAYER);
    //        layeredPane.add(baseBox,JLayeredPane.DEFAULT_LAYER);
            firstPanel.add(baseBox);
    //        opePanel.add(hiLabel,BorderLayout.NORTH);
    //        setLayeredPane(layeredPane);
            card.show(allPanel,"firstPanel");
            setMyFont(font,showOpe,showMes,showCal,spaceLabel,opeLabel);
            hiLabel.setFont(font01);
            add(allPanel);
            mesWin = new MessageWindow();
    
    //        this.MesPanel = mesWin.allPanel;
        }
    
        public void setMyFont(Font font,JComponent...x){
            for(JComponent c:x){
                c.setFont(font);
            }
        }
    
        public void setBox(){
            opeLabel = new JLabel("功能选项");
            spaceLabel = new JLabel("               ");
            box1 = Box.createVerticalBox();
            box1.add(Box.createVerticalStrut(50));
            box1.add(opeLabel);
            box1.add(Box.createVerticalStrut(25));
            box1.add(showCal);
            box1.add(Box.createVerticalStrut(50));
            box1.add(showMes);
            box1.add(Box.createVerticalStrut(50));
            box1.add(showOpe);
            box2 = Box.createVerticalBox();
    //        box2.add(Box.createVerticalStrut(50));
            box2.add(hiLabel);
            box2.add(Box.createVerticalStrut(50));
            box2.add(spaceLabel);
            box2.add(Box.createVerticalStrut(50));
            box2.add(spaceLabel);
            baseBox = Box.createHorizontalBox();
            baseBox.add(box1);
            baseBox.add(Box.createHorizontalStrut(100));
            baseBox.add(box2);
            baseBox.setOpaque(false);
            box1.setOpaque(false);
            box2.setOpaque(false);
        }
    
        public void actionPerformed(ActionEvent ae){
            if(ae.getSource()==showCal){
                card.show(allPanel,"CalPanel");
            }
            if(ae.getSource()==showMes){
                card.show(allPanel,"MesPanel");
            }
            if(ae.getSource()==showOpe){
                card.show(allPanel,"OpePanel");
            }
        }
    }
    
    class MessageWindow implements ActionListener{    //还有节假日的图片与信息没填
        Box baseBox;
        Box box1;
        Box box2;
        InitWindow view;
        JLabel imageLabelOfSolar;
        JLabel imageLabelOfFesti;
        JLabel showLabel;
        CardLayout card = null;
        JTextArea showAreaSolar;
        JTextArea showAreaFesti;
        JPanel panelOfSolar;
        JPanel panelOfFesti;
        JPanel allPanel;   //在主窗口显示的面板,以cardlayout布局
        JPanel firstPanel;
        ImageIcon icon;
        JComboBox<String>comboBoxOfSolar;
        JComboBox<String>comboBoxOfFesti;
        JButton enterSolar;
        JButton enterFesti;
        JButton solarButton,festiButton;
        JButton solarToFirst,festiToFirst,firstToMain;
        Font font;
        File file=null;
        FileReader read=null;
        BufferedReader reader=null;
        MessageWindow(){
            init();
            allPanel.setBounds(200,200,700,500);
    //        allPanel.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            allPanel.setVisible(true);
    //        allPanel.setTitle("查看节气");
            allPanel.validate();
        }
        public void init(){
            font = new Font("微软雅黑",Font.PLAIN,20);
            card = new CardLayout();
            setSolarPanel();
            setFestiPanel();
            setFirstPanel();
            allPanel = new JPanel();
            allPanel.setLayout(card);
            allPanel.add("solar",panelOfSolar);
            allPanel.add("festi",panelOfFesti);
            allPanel.add("first",firstPanel);
            card.show(allPanel,"first");
            enterFesti.addActionListener(this);
            enterSolar.addActionListener(this);
            solarButton.addActionListener(this);
            festiButton.addActionListener(this);
            solarToFirst.addActionListener(this);
            festiToFirst.addActionListener(this);
            setMyFont(font,solarButton,festiButton,solarToFirst,festiToFirst,firstToMain);
        }
        public void actionPerformed(ActionEvent ae){
            if(ae.getSource()==firstToMain){
                view.card.show(view.allPanel,"firstPanel");
            }
            if(ae.getSource()==solarButton){
                card.show(allPanel,"solar");
            }
            if(ae.getSource()==festiButton){
                card.show(allPanel,"festi");
            }
            if(ae.getSource()==solarToFirst){
                card.show(allPanel,"first");
            }
            if(ae.getSource()==festiToFirst){
                card.show(allPanel,"first");
            }
            if(ae.getSource()==enterFesti){
                //这里要用文件操作
                showAreaFesti.setText(null);
                String str = comboBoxOfFesti.getSelectedItem().toString();
                icon = new ImageIcon(str+".png");
                imageLabelOfFesti.setIcon(icon);
                file = new File("festival.txt");
                try{
                    read = new FileReader(file);
                    reader = new BufferedReader(read);
                    String tar=null;
                    while((tar=reader.readLine())!=null){
                        if(tar.equals("0000"+str)){
                            String content = reader.readLine();
                            for (int i = 0; i < content.length(); i++) {
                                showAreaFesti.append(""+content.charAt(i));
                                if(i%8==0){
                                    showAreaFesti.append("\n");
                                }
                            }
                        }
                    }
                    reader.close();
                    read.close();
                }
                catch (IOException ioexp){
                    showAreaSolar.setText("无资料");
                }
            }
            if(ae.getSource()==enterSolar){
                showAreaSolar.setText(null);
                String str = comboBoxOfSolar.getSelectedItem().toString();
                icon = new ImageIcon(str+".png");
                imageLabelOfSolar.setIcon(icon);
                file = new File("solar.txt");
                try{
                    read = new FileReader(file);
                    reader = new BufferedReader(read);
                    String tar=null;
                    while((tar=reader.readLine())!=null){
                        if(tar.equals("0000"+str)){
                            String content = reader.readLine();
                            for (int i = 0; i < content.length(); i++) {
                                showAreaSolar.append(""+content.charAt(i));
                                if(i%8==0){
                                    showAreaSolar.append("\n");
                                }
                            }
                        }
                    }
                    reader.close();
                    read.close();
                }
                catch (IOException ioexp){
                    showAreaSolar.setText("无资料");
                }
                //showArea里面的内容也要用到文件操作
            }
        }
    
        public void setMyFont(Font font,JComponent...x){
            for(JComponent c:x){
                c.setFont(font);
            }
        }
    
        public void setSolarPanel(){
            solarToFirst = new JButton("返回");
            panelOfSolar = new JPanel();
            BorderLayout bord = new BorderLayout();
    //        panelOfSolar.setLayout(bord);
            enterSolar = new JButton("确定");
            //二十四节气面板加入box和显示图片的label
            baseBox = Box.createHorizontalBox();
            showAreaSolar = new JTextArea(10,10);
            showAreaSolar.setEditable(false);
            imageLabelOfSolar = new JLabel();
            imageLabelOfSolar.setSize(250,300);
            /
    //        icon = new ImageIcon("原始.png");
    //        imageLabelOfSolar.setIcon(icon);
            /
            showLabel = new JLabel("请选择节气");
            comboBoxOfSolar = new JComboBox<>();
            String[]solar={"立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至","小寒","大寒"};
            for (String s : solar) {
                comboBoxOfSolar.addItem(s);
            }
            box1 = Box.createHorizontalBox();
            box1.add(new JScrollPane(showAreaSolar));
            box1.add(Box.createHorizontalStrut(12));
            box1.add(imageLabelOfSolar);
            box2 = Box.createHorizontalBox();
            box2.add(solarToFirst);
            box2.add(Box.createHorizontalStrut(10));
            box2.add(showLabel);
            box2.add(Box.createHorizontalStrut(10));
            box2.add(comboBoxOfSolar);
            box2.add(Box.createHorizontalStrut(30));
            box2.add(enterSolar);
            baseBox = Box.createVerticalBox();
            baseBox.add(box2);
            baseBox.add(Box.createVerticalStrut(20));
            baseBox.add(box1);
            panelOfSolar.add(baseBox,BorderLayout.CENTER);
            setMyFont(font,showAreaSolar,showLabel,comboBoxOfSolar,enterSolar);
        }
    
        public void setFestiPanel(){
            festiToFirst = new JButton("返回");
            String[] festi={"元旦","春节","清明节","妇女节","植树节","劳动节","青年节","端午节","儿童节","建党节","建军节","教师节","中秋节","国庆节"};
            comboBoxOfFesti = new JComboBox<>();
            for(String s:festi){
                comboBoxOfFesti.addItem(s);
            }
            showAreaFesti = new JTextArea(10,10);
            showAreaFesti.setEditable(false);
            showLabel = new JLabel("请选择节日:");
            enterFesti = new JButton("确定");
            panelOfFesti = new JPanel();
            imageLabelOfFesti = new JLabel();
    //        icon = new ImageIcon("原始.png");
    //        imageLabelOfFesti.setIcon(icon);
            imageLabelOfFesti.setSize(250,300);
            box1 = Box.createHorizontalBox();
            box1.add(festiToFirst);
            box1.add(Box.createHorizontalStrut(10));
            box1.add(showLabel);
            box1.add(Box.createHorizontalStrut(10));
            box1.add(comboBoxOfFesti);
            box1.add(Box.createHorizontalStrut(30));
            box1.add(enterFesti);
            box2 = Box.createHorizontalBox();
            box2.add(new JScrollPane(showAreaFesti));
            box2.add(Box.createHorizontalStrut(20));
            box2.add(imageLabelOfFesti);
            baseBox = Box.createVerticalBox();
            baseBox.add(box1);
            baseBox.add(Box.createVerticalStrut(20));
            baseBox.add(box2);
    //        panelOfFesti.add(northPanel,BorderLayout.NORTH);
            panelOfFesti.add(baseBox,BorderLayout.CENTER);
            setMyFont(font,comboBoxOfFesti,showLabel,showAreaFesti,enterFesti);
        }
    
        public void setPanel(JPanel panel){
            this.allPanel=panel;
        }
    
        public void setView(InitWindow view){
            this.view=view;
        }
    
        public void setFirstPanel(){
            firstToMain = new JButton("返回");
            firstToMain.addActionListener(this);
            firstPanel = new JPanel();
            BorderLayout bord = new BorderLayout();
            firstPanel.setLayout(bord);
            solarButton = new JButton("查看二十四节气");
            festiButton = new JButton("查看节日");
            box1 = Box.createVerticalBox();
            box1.add(Box.createVerticalStrut(40));
            box1.add(solarButton);
            box2=Box.createVerticalBox();
            box2.add(Box.createVerticalStrut(40));
            box2.add(festiButton);
            baseBox = Box.createHorizontalBox();
            baseBox.add(Box.createHorizontalStrut(50));
            baseBox.add(box1);
            baseBox.add(Box.createHorizontalStrut(50));
            baseBox.add(box2);
            baseBox.add(Box.createHorizontalStrut(50));
            box1 = Box.createVerticalBox();
            box1.add(Box.createVerticalStrut(40));
            box1.add(firstToMain);
            baseBox.add(box1);
            baseBox.add(Box.createHorizontalStrut(50));
            firstPanel.add(baseBox,BorderLayout.CENTER);
        }
    }
    
    class OperateWindow implements ActionListener, ItemListener {
        CardLayout card = null;
        Box baseBox;
        Box box1;
        Box box2;
        Box box3;
        JPanel allPanel;
        JPanel viewPanel;
        JPanel addPanel;
        JPanel firstPanel;
        JPanel selectPanel;
        JButton viewButton;
        JButton addButton;
        JCheckBox[] checkArray;
        JButton enterOfView;
        JButton enterOfAdd;
        JButton viewBack;
        JButton addBack;
        JButton firstBack;
        JButton cleanButton;
        JComboBox<String> comboBox;
        JComboBox<String> comboBoxHour;
        JComboBox<String> comboBoxMinute;
        JTextArea inputArea;
        JLabel tipLabel;
        JLabel dateLabel;
        JLabel titleLabel;
        Font font01, font02;
        File file = null;
        FileReader read = null;
        BufferedReader Reader = null;
        FileWriter write = null;
        BufferedWriter Writer = null;
        InitWindow view;
    
        OperateWindow() {
            init();
            allPanel.setVisible(true);
            allPanel.setBounds(200, 200, 700, 500);
        }
    
        public void init() {
            font01 = new Font("微软雅黑", Font.PLAIN, 15);
            font02 = new Font("宋体", Font.BOLD, 20);
            checkArray = new JCheckBox[10];
            comboBoxHour = new JComboBox<>();
            comboBoxMinute = new JComboBox<>();
            for (int i = 0; i < 24; i++) {
                String hour = i + "";
                comboBoxHour.addItem(hour);
            }
            for (int i = 0; i < 60; i++) {
                String minute = i + "";
                comboBoxMinute.addItem(minute);
            }
    
            for (int i = 0; i < 10; i++) {
                checkArray[i] = new JCheckBox();
                checkArray[i].addItemListener(this);
            }
    
            createViewPanel();
            createAddPanel();
            createFirstPanel();
    
            allPanel = new JPanel();
            card = new CardLayout();
            allPanel.setLayout(card);
            allPanel.add("view", viewPanel);
            allPanel.add("add", addPanel);
            allPanel.add("first", firstPanel);
            card.show(allPanel, "first");
            setMyFont(font02, enterOfAdd, enterOfView, tipLabel, inputArea, addButton, viewButton, comboBoxHour, comboBoxMinute, dateLabel, firstBack);
            addButton.addActionListener(this);
            viewButton.addActionListener(this);
        }
    
        public void createViewPanel() {
            viewPanel = new JPanel();
            BorderLayout bord = new BorderLayout();
            viewPanel.setLayout(bord);
            tipLabel = new JLabel("您还有以下未完成的事项");
            enterOfView = new JButton("确定");
            viewBack = new JButton("返回");
            cleanButton = new JButton("清除");
            viewBack.addActionListener(this);
            enterOfView.addActionListener(this);
            cleanButton.addActionListener(this);
            tipLabel = new JLabel("您还有以下日程没完成");
    
            setMyFont(font02, tipLabel, cleanButton);
            showViewPanel();
        }
    
        public void setView(InitWindow view) {
            this.view = view;
        }
    
        public void createAddPanel() {
            addPanel = new JPanel();
            BorderLayout bord = new BorderLayout();
            addPanel.setLayout(bord);
            tipLabel = new JLabel("在未来一周内添加事件");
            inputArea = new JTextArea(5, 10);
            inputArea.requestFocus();
            comboBox = new JComboBox<>();
            enterOfAdd = new JButton("确定");
            enterOfAdd.addActionListener(this);
            addBack = new JButton("返回");
            addBack.addActionListener(this);
            LocalDate date = LocalDate.now();
            int count = 0;
            String str = null;
            setMyFont(font02, comboBox, tipLabel);
            setMyFont(font01, inputArea);
            while (count < 7) {
                int year = date.getYear();
                int month = date.getMonthValue();
                int Day = date.getDayOfMonth();
                str = year + "-" + month + "-" + Day;
                comboBox.addItem(str);
                date = date.plusDays(1);
                count++;
            }
            box1 = Box.createVerticalBox();
            box1.add(inputArea);
            box1.add(Box.createVerticalStrut(100));
    
            box2 = Box.createHorizontalBox();
            box2.add(addBack);
            box2.add(Box.createHorizontalStrut(10));
            dateLabel = new JLabel("选择日期");
            dateLabel.setFont(font02);
            box2.add(dateLabel);
            box2.add(Box.createHorizontalStrut(10));
            box2.add(comboBox);
            box2.add(Box.createHorizontalStrut(10));
            dateLabel = new JLabel("选择小时");
            dateLabel.setFont(font02);
            box2.add(dateLabel);
            box2.add(Box.createHorizontalStrut(10));
            box2.add(comboBoxHour);
            box2.add(Box.createHorizontalStrut(10));
            dateLabel = new JLabel("选择分钟");
            box2.add(dateLabel);
            box2.add(Box.createHorizontalStrut(10));
            box2.add(comboBoxMinute);
    
            addPanel.add(box2, BorderLayout.NORTH);
            addPanel.add(box1, BorderLayout.CENTER);
            addPanel.add(enterOfAdd, BorderLayout.SOUTH);
        }
    
        public void createFirstPanel() {
            firstBack = new JButton("返回");
            firstBack.addActionListener(this);
            firstPanel = new JPanel();
            BorderLayout bord = new BorderLayout();
            firstPanel.setLayout(bord);
            viewButton = new JButton("查看日程");
            addButton = new JButton("添加日程");
            box1 = Box.createVerticalBox();
            box1.add(Box.createVerticalStrut(40));
            box1.add(viewButton);
            box2 = Box.createVerticalBox();
            box2.add(Box.createVerticalStrut(40));
            box2.add(addButton);
            baseBox = Box.createHorizontalBox();
            baseBox.add(Box.createHorizontalStrut(50));
            baseBox.add(box1);
            baseBox.add(Box.createHorizontalStrut(50));
            baseBox.add(box2);
            baseBox.add(Box.createHorizontalStrut(50));
            box1 = Box.createVerticalBox();
            box1.add(firstBack);
            box1.add(Box.createVerticalStrut(80));
            baseBox.add(box1);
            baseBox.add(Box.createHorizontalStrut(50));
            firstPanel.add(baseBox, BorderLayout.CENTER);
        }
    
        public void actionPerformed(ActionEvent ae) {
            if (ae.getSource() == enterOfAdd) {
                try {
                    file = new File("ToDoList.txt");
                    read = new FileReader(file);
                    Reader = new BufferedReader(read);
                    String str01 = null;
                    int count = 0;
                    while ((str01 = Reader.readLine()) != null) {
                        count++;
                    }
                    if (count == 10) {
                        JLabel warn = new JLabel("日程已经超出最大数!");
                        warn.setFont(font02);
                        JOptionPane.showMessageDialog(allPanel, warn, "超限提示框", JOptionPane.ERROR_MESSAGE);
                        inputArea.setText(null);
                        return;
                    }
                    Reader.close();
                    read.close();
    
                    int hour = Integer.parseInt(comboBoxHour.getSelectedItem().toString());
                    int minute = Integer.parseInt(comboBoxMinute.getSelectedItem().toString());
                    String hour02 = null;
                    String minute02 = null;
                    if (hour < 10) {
                        hour02 = "0" + hour;
                    } else {
                        hour02 = hour + "";
                    }
                    if (minute < 10) {
                        minute02 = "0" + minute;
                    } else {
                        minute02 = minute + "";
                    }
                    if (inputArea.getText().equals("")) {
                        JLabel warn = new JLabel("请至少输入一个字符");
                        warn.setFont(font02);
                        JOptionPane.showMessageDialog(this.allPanel, warn, "提醒输入框", JOptionPane.ERROR_MESSAGE);
                        return;
                    }
                    String str02 = inputArea.getText().replace("\n", "");
                    if (str02.length() == 0) {
                        JOptionPane.showMessageDialog(this.allPanel, "请至少输入一个字符", "提醒款", JOptionPane.ERROR_MESSAGE);
                        inputArea.setText(null);
                        inputArea.requestFocus();
                        return;
                    }
                    String mess = comboBox.getSelectedItem().toString() + "-" + hour02 + ":" + minute02 + str02;
                    file = new File("ToDoList.txt");
                    write = new FileWriter(file, true);
                    Writer = new BufferedWriter(write);
                    Writer.write(mess + "\n");
                    Writer.close();
                    write.close();
                } catch (IOException exp) {
                }
                inputArea.setText(null);
                inputArea.requestFocus();
                JLabel warn = new JLabel("创建日程成功!");
                warn.setFont(font02);
                JOptionPane.showMessageDialog(this.allPanel, warn, "提示框", JOptionPane.ERROR_MESSAGE);
            }
            if (ae.getSource() == viewButton) {
                card.show(allPanel, "view");
                showViewPanel();
            }
            if (ae.getSource() == addButton) {
                card.show(allPanel, "add");
            }
            if (ae.getSource() == viewBack) {
                card.show(allPanel, "first");
            }
            if (ae.getSource() == addBack) {
                card.show(allPanel, "first");
            }
            if (ae.getSource() == firstBack) {
                view.card.show(view.allPanel, "firstPanel");
            }
            if (ae.getSource() == cleanButton) {
                int n = JOptionPane.showConfirmDialog(this.allPanel, "确认全部清除?", "提醒框", JOptionPane.YES_NO_OPTION);
                if (n == JOptionPane.YES_OPTION) {
                    file = new File("ToDoList.txt");
                    try {
                        FileOutputStream out = new FileOutputStream(file);
                    }
                    catch (IOException exp) {}
                    showViewPanel();
                }
            }
            if (ae.getSource() == enterOfView) {
                showViewPanel();
            }
        }
    
        public void setMyFont(Font font, JComponent... x) {
            for (JComponent c : x) {
                c.setFont(font);
            }
        }
    
        public void showViewPanel() {
            file = new File("ToDoList.txt");
            box2=Box.createVerticalBox();
    //        if (file.length() == 0) {
    //            JOptionPane.showMessageDialog(this.allPanel, "没有安排任何日程", "提醒框", JOptionPane.ERROR_MESSAGE);
    //        }
            try {
                read = new FileReader(file);
                Reader = new BufferedReader(read);
                String str = null;
                int i = 0;
                String day01 = null;
                String day02 = null;
                while ((str = Reader.readLine()) != null) {
                    day01 = str.substring(0, 10);
                    if (day02 != null) {
                        if (!day02.equals(day01)) {
                            //如果上一条的日期和现在一条的日期不一样,则另外创建一个titlLabel;
                            titleLabel = new JLabel(day01);
                            titleLabel.setFont(font01);
                            box2.add(titleLabel);
                            box2.add(Box.createVerticalStrut(5));
                        }
                    }
                    if (day02 == null) {
                        titleLabel = new JLabel(day01);
                        titleLabel.setFont(font01);
                        box2.add(titleLabel);
                        box2.add(Box.createVerticalStrut(5));
                    }
                    day02 = day01;
    
                    String rest = str.substring(10);
                    String time = rest.substring(1, 6);  //几点几分
                    String content = rest.substring(6); //代办事项
                    checkArray[i] = new JCheckBox(content + "(" + time + ")");
                    checkArray[i].setFont(font02);
                    checkArray[i].addItemListener(this);
                    box2.add(checkArray[i]);
                    box2.add(Box.createVerticalStrut(1));
                    i++;
                }
                Reader.close();
                read.close();
    
            } catch (IOException ioexp) {
            }
            viewPanel.removeAll();
    
            box1=Box.createHorizontalBox();
            box1.add(viewBack);
            box1.add(Box.createHorizontalStrut(20));
            tipLabel = new JLabel("您还有以下日程未完成:");
            tipLabel.setFont(font02);
            box1.add(tipLabel);
    
            baseBox = Box.createHorizontalBox();
            baseBox.add(Box.createHorizontalStrut(200));
            baseBox.add(enterOfView);
            baseBox.add(Box.createHorizontalStrut(20));
            baseBox.add(cleanButton);
            baseBox.add(Box.createHorizontalStrut(20));
    
            viewPanel.add(box1, BorderLayout.NORTH);
            viewPanel.add(box2,BorderLayout.CENTER);
            viewPanel.add(baseBox, BorderLayout.SOUTH);
        }
    
        public void itemStateChanged(ItemEvent it) {
            JCheckBox check = (JCheckBox) it.getSource();
            file = new File("ToDoList.txt");
            LinkedList<String> list = new LinkedList<>();
            try {
                read = new FileReader(file);
                Reader = new BufferedReader(read);
                String str = null;
                while ((str = Reader.readLine()) != null) {
                    String regax = "[1234567890.:-]";
                    String str1 = str.replaceAll(regax, "");
    //                System.out.println(str1);
                    if (!check.getText().contains(str1)) {
                        list.add(str);
                    }
                }
                try {
                    FileOutputStream out = new FileOutputStream(file);
                }
                catch (IOException ioe) {}
                Reader.close();
                read.close();
                write = new FileWriter(file);
                Writer = new BufferedWriter(write);
                Iterator<String> iter = list.iterator();
                while (iter.hasNext()) {
                    String tar = iter.next();
    //                System.out.println(tar);
                    Writer.write(tar + "\n");
                }
                Writer.close();
                write.close();
            }
            catch (IOException exp) {}
        }
    }
    
    
    

    展开全文
  • PHP 自制日历

    2014-09-26 09:26:55
    在 http://www.cnblogs.com/strick/p/3988764.html 有说明解释
  • 自制日历功能

    2021-01-25 15:17:39
    1,获取当前日期数据 getData() { let Data = new Date() let day = Data.getDate() let mounth = Data.getMonth()+1 this.mounth = mounth let year = Data.getFullYear() ...

    1,获取当前日期数据

    	  	getData() {
      			let Data = new Date()
      			let day = Data.getDate()
      			let mounth = Data.getMonth()+1
      			this.mounth = mounth
      			let year = Data.getFullYear()
      			this.year = year
      			this.setCalendar(year, mounth)
    			},
    

    2,获取当前月份日期排列

    	  	setCalendar(year, mounth) {
    				//获取月份的总天使
    			  let d = new Date(year,mounth,0);
    				let days=d.getDate();
    				//获取当前月份第一天的周几
    				let w = new Date(year,mounth-1,1);
    				let week = w.getDay();
    				let weeks=[]
    				let allDays = days+week-1
    				let constDayOfWeeks = [];
    				for(let j=week;j<=allDays;j++){
    					constDayOfWeeks.push({week:j%7,day:j-week+1})
    				}
    				let week1=[]
    				let week2=[]
    				constDayOfWeeks.forEach((n, index)=>{
    					if (n.week == 0 && index !==0) {
    						week2.push(week1)
    						week1 = []
    						week1.push(n)
    					} else if (index == constDayOfWeeks.length-1) {
    						week1.push(n)
    						week2.push(week1)
    					} else {
    						week1.push(n)
    					}
    				})
    				let week3 = []
    				week2.forEach((n)=>{
    					if(n.length !=7) {
    						if (n[0].week == 0) {
    							let len = 7 - n.length
    							let arr = Array(len)
    							n = [...n, ...arr]
    						} else {
    							let len = 7 - n.length
    							let arr = Array(len)
    							n = [...arr, ...n]
    						}
    					}
    					week3.push(n)
    				})
    	  			this.weeksAll = week3
    	  	},
    

    3,html样式

    <table class="table-1 weeks" border="1" cellspacing="0" cellpadding="0">
    				<tr>
    					<th>星期日</th>
    					<th>星期一</th>
    					<th>星期二</th>
    					<th>星期三</th>
    					<th>星期四</th>
    					<th>星期五</th>
    					<th>星期六</th>
    				</tr>
    				<tr v-for="(item, index) in weeksAll" :key="index">
    					<td v-for="(items, index1) in item" :key="index1">
    						<div class="datas" v-if="items != undefined" :class="{'datas1': studyList[`${year}-${mounth>9?mounth+'': '0'+mounth}-${items.day>9?items.day+'':'0'+items.day}`] && !studyList[`${year}-${mounth>9?mounth+'': '0'+mounth}-${items.day>9?items.day+'':'0'+items.day}`]['have'] || !studyList[`${year}-${mounth>9?mounth+'': '0'+mounth}-${items.day>9?items.day+'':'0'+items.day}`]}">
    							{{items == undefined? '': items.day}}
    						</div>
    					</td>
    				</tr>
    			</table>
    
    css
    	.weeks {
    		& .datas {
    				width: 100%;
    				height: 30px;
    				text-align: center;
    				line-height: 30px;
    				background: #ed7d31;
    		}
    		& .datas1 {
    				width: 100%;
    				font-size: 60px;
    				font-weight: bold;
    				text-align: center;
    				height: 155px;
    				line-height: 155px;
    				background: none;
    				
    		}
    	}
    

    4,切换月份

    			//上一月
    			upMounth () {
    				if (this.mounth == 1) {
    					this.mounth = 12
    					this.year = this.year - 1
    				} else {
    					this.mounth = this.mounth - 1
    				}
      			this.setCalendar(this.year, this.mounth)
    			},
    			//下一月
    			downMounth() {
    				if (this.mounth == 12) {
    					this.mounth = 1
    					this.year = this.year + 1
    				} else {
    					this.mounth = this.mounth + 1
    				}
      			this.setCalendar(this.year, this.mounth)
    			},
    
    展开全文
  • vue自制日历组件

    千次阅读 2018-04-03 20:16:07
    //显示日历部分 var firstday; var today = dateNow; var yy = today.getFullYear(); this.currentYear=yy; var mm = today.getMonth() + 1;//today=2;mm=3 this.currentMonth=mm-1;//this.curr=2 var dd =...

    效果图:

    代码:

    <template>
       <div id="calender">
                    <div id="celender_head">
                        <div id="left" class="celender_head" @click="left()">←</div>
                        <div id="celender_head_inner" class="celender_head"><p >{{header}}</p></div>
                        <div id="right" class="celender_head" @click="right()">→</div>
                    </div>
                    <div id="calender_body">
                        <table>
                            <tr class='head'>
                                <td v-for="head in heads" >{{head}}</td>
                            </tr>
                             <tr v-for="item in show">
                            <td :class="{now: item1.now, last_month:item1.attr == 'last_month',next_month:item1.attr == 'next_month'}" v-for="item1 in item ">{{item1.num}} </td>
                            </tr>
                        </table>
                    </div>
                    <div id="calender_foot">
                        <p @click="backToday">回到今天</p>
                    </div>
                </div>
    </template>
    
    <script>
    export default {
    created(){
         this.setCalender(new Date())
    }, 
    
      methods:{
          initline:function(){
              this.datas=new Array()
              this.show=new Array();
         
          },
        backToday:function(){
            this.setCalender(new Date())
        },
        getcurrentDates:function (calender_Date) {//传入正常的Date()类型数据
            this.initline()
            var months=calender_Date.getMonth();
            months=months+1;
            calender_Date.setMonth(months);
            calender_Date.setDate(0)
    
    
            return calender_Date.getDate();
        },
        getlastDates:  function (calenderdDate) {//传入正常的Date()类型数据
            var curDate = calenderdDate;
            curDate.setDate(0);
            return curDate.getDate();
        },
        left:function(){
        this.initline()
        var yy=this.currentYear;
        var mm=this.currentMonth;
        var dd=1
        if(yy==new Date().getFullYear()&&mm==new Date().getMonth()+1){
         dd=new Date().getDate();
        }
        if(mm==0){
            mm=12;yy=yy-1;
            this.currentMonth=mm;
            this.currentYear=yy;
        }
        var calenderrDate=yy+"-"+mm+"-"+dd;
        this.setCalender(new Date(calenderrDate));
    },
        right:function(){
            this.initline()
        var yy=this.currentYear;
        var mm=this.currentMonth+2;
        var dd=1
        if(yy==new Date().getFullYear()&&mm==new Date().getMonth()+1){
             dd=new Date().getDate();
        }
        if(mm>12){
            mm=1;yy++;
            this.currentMonth=mm;
            this.currentYear=yy;
        }
    var calender__Date=yy+"-"+mm+"-"+dd;
    this.setCalender(new Date(calender__Date));
    },
          setCalender:function(dateNow){
            //显示日历部分
            var firstday;
            var today = dateNow;    
            var yy = today.getFullYear();
            this.currentYear=yy;
            var mm = today.getMonth() + 1;//today=2;mm=3
            this.currentMonth=mm-1;//this.curr=2
            var dd = today.getDate();
            this.currentDay=dd;//30
            firstday = yy + "-" + mm + "-1";//2018-3-1
            //本月第一天是星期几,也表示前面有几个空的天数
            var firstday_day = new Date(firstday).getDay();
            //日历头
            this.header=yy+"年"+mm+"月";
            var cur_days = this.getcurrentDates(today);
            //上一月有多少天
            var last_days = this.getlastDates(dateNow); 
            
            //上个月从哪天开始出现
            var last_first_day = last_days - firstday_day + 1;
            //firstline
            //存上个月的日期
            for (var i = last_first_day; i <= last_days;i++) {
                var date=new Object(); 
                date.num=i;
                date.attr='last_month'
                date.now=false
                this.datas.push(date);
                // this.dateData.firstline.push(date);
            }
            //temp存放换行前上一个数据
            //下一行第一个数字
            var num_second = 7 - firstday_day + 1;
            //存本月日期
            for (var i = 1; i <= cur_days; i++) {
                var date=new Object();
                date.num=i;
                date.attr='this_month'
                if(i == this.currentDay && this.currentMonth == new Date().getMonth()&&this.currentYear==new Date().getFullYear()){
                    date.now=true
                }else{
                    date.now=false
                }
                this.datas.push(date);
            }
            for(var i=1;i<=42-cur_days-(last_days-last_first_day+1);i++){
                var date=new Object();
                date.num=i;
                date.attr='next_month'
                this.datas.push(date);
            }
            
            var k=0;
            for(var i=0;i<6;i++){
                var line=new Array();
                for(var j=0;j<7;j++){
                    line.push(this.datas[k++]);
                }
                this.show.push(line);
            }
           
      }
      },
      data (){
        return {
                body:'',header:'',currentYear:'',currentMonth:'',currentDay:'',
                heads:["日","一","二","三","四","五","六"],
               
                datas:new Array(),
                show:new Array()
            }
        }
    
    }
    </script>
    <style lang="less">
    
    @red: red;
    @gray:rgb(248,248,248);
    
    #calender{
        overflow:auto ;
        position: relative;
        top: 73px;
        left: 939px;
        width: 280px;
        border:2px solid rgb(170, 105, 231);
    
    #celender_head{
        height: 40px;
        width: 280px;
        background-color: blue;
    
    .celender_head{ 
        line-height: 40px;
        text-align: center;
        height: 40px;
    }
    
    #left{
        height: 40px;
        width: 40px;
        float: left;
    }
    
    #celender_head_inner{
        height: 40px;
        width: 80px;
        float: left;
        margin-left: 60px;
        line-height:20px
    }
    
    #right{
        height: 40px;
        width: 40px;
        float: left;
        margin-left: 60px
    }
    
          p{
            color: white;
            font-size: 10px;
            text-align: center;
            }
        }
    
     #calender_body {
         
        .head td:hover{
        background-color: @gray
        }
    
        td{
        width: 40px;
        height: 40px;
        text-align: center;
        line-height: 40px;
        border-radius: 50%;
            &:hover{
            background-color: @red;
            }
            &.now {
            color: @red;
            }
            
    }
        .last_month {
             color:lightgray;
             &:hover {
                  background-color: @gray
                     }
    }
    
        .next_month{
        color:lightgray;
            &:hover {
        background-color: @gray
            }
    }
    }
    
    
    #calender_foot{
        background-color: @gray;
        text-align: center;
        line-height:40px;
        p{
        color: blue;
        font-size: 10px;
        }
    }
    }
    
    
    
    
    
    
    </style>
    

     

    展开全文
  • PS绘制ICO图标在UI设计师的领域,游戏、WEB前端以及App的界面设计都是最重要的设计方向,此次带来的是APP图标之——日历的设计。和之前一样我们可以利用PS的形状工具来绘制一个圆角矩形。然后我们找到图层面板,开启...
  • VC6 自制日历控件

    2010-08-28 10:03:36
    VC6 自制日历控件VC6 自制日历控件VC6 自制日历控件
  • 自制日历控件(jquery+html)所用素材+源代码
  • 1.创建数据库的方法:public void onCreate(SQLiteDatabase db){String sql = "CREATE TABLE[calendar]("+"[_id] INTEGER PRIMARY KEY AUTOINCREMENT,"+"[text] text"+")";db.execSQL(sql);}这样对齐看起来很方便.2....
  • 日历窗体模块

    2019-01-10 13:28:41
    工作中输入日期有没有觉的很麻烦,我们可以用 VBA在EXCEL中做一个日历窗体
  • &lt;style&gt; *{margin: 0px; padding: 0px;} &lt;/style&gt; &lt;input type="text" name="year" onclick="Canlender.getYear($(this))"...year"
  • 用C++ Builder 做的简单日历源码演示,提供给初学者参考。
  • 不换行显示的日历,可以在表格的第三行里填写你要显示的内容
  • 自制日历软件源码,透明窗体,显示日历,不碍眼。
  • 新手小白无聊时做的一个 日历控件,需要的朋友可以借鉴下,高手大神也可以指点一下。 核心代码 获取某年某月有多少天 /// 获取某年某月有多少天 /// </summary> /// <param name="_year">年份</...
  • 自制简易日历

    2018-07-11 11:46:47
    自制简易日历,方便实用。点击即可实用,用C语言开发的
  • 自制日历组件

    2012-03-11 13:00:00
    <<月份>> SUNMONTUEWEDTHUFRISAT ...
  • 鉴于项目所需 自绘了一个日历控件 MFC 自绘日历控件 Calendar自绘 其中day的索引获取还没实现 这个很简单 可以自己添加一下
  • 自制日历手机数据库(实现SQLiteOpenHelper) 新建一个继承Activity类的SQLiteOpenHelperActivity,并设置布局文件为:sqliteopenhelper.xml。 首先定义布局文件: xml version="1.0" encoding="utf-8...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 1,420
精华内容 568
关键字:

如何自制日历