欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

  1. Java實(shí)現(xiàn)的日歷功能完整示例

     更新時(shí)間:2019年02月25日 10:44:11   作者:c_jian  
    這篇文章主要介紹了Java實(shí)現(xiàn)的日歷功能,結(jié)合完整實(shí)例形式分析了Java日歷功能相關(guān)的日期時(shí)間獲取、計(jì)算、顯示等操作技巧,需要的朋友可以參考下

    本文實(shí)例講述了Java實(shí)現(xiàn)的日歷功能。分享給大家供大家參考,具體如下:

    應(yīng)用名稱:Java日歷

    用到的知識(shí):Java GUI編程,日期操作

    開發(fā)環(huán)境:win8+eclipse+jdk1.8

    功能說明:一個(gè)很簡(jiǎn)單的萬年歷,可以選擇年份和月份,也可以用按鈕翻頁,日歷會(huì)實(shí)時(shí)更新日期,最下方會(huì)顯示當(dāng)前操作系統(tǒng)的時(shí)間。

    效果圖:

    源代碼:

    CalendarFrame.java

    import java.awt.BorderLayout;
    import java.awt.GridLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.border.BevelBorder;
    import javax.swing.border.SoftBevelBorder;
    public class CalendarFrame extends JFrame implements ActionListener{
      /**
       * @author Nut
       * 2016.01.13
       */
      private static final long serialVersionUID = -7260798316896145633L;
      JLabel labelDay[] = new JLabel[42];
      JButton titleName[] = new JButton[7];
      String name[]={"日","一","二","三","四","五","六"};
      JButton nextMonth,previousMonth;
      JComboBox choiceYear,choiceMonth;
      Calendarbean calendar;
      JLabel showYear,showMonth;
      JLabel showmessage=new JLabel("",JLabel.CENTER);
      int year = 2011,month=2;
      //構(gòu)造方法初始化界面
      public CalendarFrame(){
        JPanel pCenter = new JPanel();
        pCenter.setLayout(new GridLayout(7,7));
        //星期欄
        for(int i=0;i<7;i++){
          titleName[i]=new JButton(name[i]);
          titleName[i].setBorder(new SoftBevelBorder(BevelBorder.RAISED));
          pCenter.add(titleName[i]);
        }
        //日期欄
        for(int i=0;i<42;i++){
          labelDay[i]=new JLabel("",JLabel.CENTER);
          labelDay[i].setBorder(new SoftBevelBorder(BevelBorder.LOWERED));
          pCenter.add(labelDay[i]);
        }
        //年月選擇欄
        choiceYear=new JComboBox();
        choiceMonth=new JComboBox();
        showYear=new JLabel("年");
        showMonth=new JLabel("月  ");
        for(int i=1990;i<2050;i++)
          choiceYear.addItem(i);
        choiceYear.addActionListener(this);
        for(int i=1;i<=12;i++)
          choiceMonth.addItem(i);
        choiceMonth.addActionListener(this);
        calendar=new Calendarbean();
        nextMonth=new JButton("下月");
        previousMonth=new JButton("上月");
        nextMonth.addActionListener(this);
        previousMonth.addActionListener(this);
        JPanel pNorth=new JPanel(),
        pSouth=new JPanel();
        pNorth.add(choiceYear);
        pNorth.add(showYear);
        pNorth.add(choiceMonth);
        pNorth.add(showMonth);
        pNorth.add(previousMonth);
        pNorth.add (nextMonth);
        pSouth.add(showmessage);
        add(pCenter,BorderLayout.CENTER);
        add(pNorth,BorderLayout.NORTH);
        add(pSouth,BorderLayout.SOUTH);
        setYearAndMonth(year,month);
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
      }
    public void setYearAndMonth(int y,int m){
      calendar.setYear(y);
      calendar.setMonth(m);
      String day[]=calendar.getCalendar();
      for(int i=0;i<42;i++)
        labelDay[i].setText(day[i]);
      SimpleDateFormat df = new SimpleDateFormat("yyyy年MM月dd日 EEEE");//設(shè)置日期格式
      showmessage.setText("系統(tǒng)時(shí)間:"+df.format(new Date()));
    }
    //事件動(dòng)作
    public void actionPerformed(ActionEvent e){
      if(e.getSource()==nextMonth){
        month=month +1;
        if(month>12)
          month=1;
        calendar.setMonth(month);
        choiceMonth.setSelectedItem(month);
        String day[]=calendar.getCalendar();
        for(int i=0;i<42;i++){
          labelDay[i].setText(day[i]);
        }
      }
      else if(e.getSource()==previousMonth){
        month=month-1;
        if(month<1)
          month=12;
        calendar.setMonth(month);
        choiceMonth.setSelectedItem(month);
        String day[]=calendar.getCalendar();
        for(int i=0;i<42;i++){
          labelDay[i].setText(day[i]);
        }
      }
      //選擇年份
      else if (e.getSource()==choiceYear){
        calendar.setYear((Integer) choiceYear.getSelectedItem());
        String day[]=calendar.getCalendar();
        for(int i=0;i<42;i++){
          labelDay[i].setText(day[i]);
          }
        }
      //選擇月份
      else if (e.getSource()==choiceMonth){
        calendar.setMonth((Integer) choiceMonth.getSelectedItem());
        String day[]=calendar.getCalendar();
        for(int i=0;i<42;i++){
            labelDay[i].setText(day[i]);
        }
      }
    //  showmessage.setText("日歷:"+calendar.getYear()+"年"+calendar.getMonth()+"月");
    }
    }
    
    

    Calendarbean.java

    import java.util.Calendar;
    public class Calendarbean {
     String day[];
     int year = 2005,month=0;
     public void setYear(int year){
       this.year=year;
     }
     public int getYear(){
       return year;
     }
     public void setMonth(int month){
       this.month=month;
     }
     public int getMonth(){
       return month;
     }
     public String[] getCalendar(){
       String a[]=new String[42];
       Calendar 日歷=Calendar.getInstance();
       日歷.set(year,month-1,1);
       int 星期幾=日歷.get(Calendar.DAY_OF_WEEK)-1;
       int day=0;
       if (month==1||month==3||month==5||month==7||month==8||month==10||month==12)
         day=31;
       if(month==4||month==6||month==9||month==11)
         day=30;
       if(month==2){
         if(((year%4==0)&&(year%100!=0))||(year%400==0))
           day=29;
         else
           day=28;
       }
       for(int i=星期幾,n=1;i<星期幾+day;i++){
         a[i]=String.valueOf(n);
         n++;
       }
       return a;
     }
    }
    
    

    CalendarMainClass.java

    public class CalendarMainClass{
      public static void main(String args[])
      {
        CalendarFrame frame = new CalendarFrame();
        frame.setBounds(100,100,360,300);
        frame.setTitle("Java日歷");
        frame.setVisible(true);
        frame.setYearAndMonth(1990,1);//設(shè)置日歷初始值為1990年1月
      }
    }
    
    

    PS:這里再為大家推薦幾款時(shí)間及日期相關(guān)工具供大家參考使用:

    Unix時(shí)間戳(timestamp)轉(zhuǎn)換工具:
    http://tools.jb51.net/code/unixtime

    在線日期/天數(shù)計(jì)算器:
    http://tools.jb51.net/jisuanqi/date_jisuanqi

    在線日期計(jì)算器/相差天數(shù)計(jì)算器:
    http://tools.jb51.net/jisuanqi/datecalc

    在線日期天數(shù)差計(jì)算器:
    http://tools.jb51.net/jisuanqi/onlinedatejsq

    更多關(guān)于java相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《java日期與時(shí)間操作技巧匯總》、《Java數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Java操作DOM節(jié)點(diǎn)技巧總結(jié)》和《Java緩存操作技巧匯總

    希望本文所述對(duì)大家java程序設(shè)計(jì)有所幫助。

    相關(guān)文章

    • Mybatis-Plus使用updateById()、update()將字段更新為null

      Mybatis-Plus使用updateById()、update()將字段更新為null

      本文主要介紹了Mybatis-Plus使用updateById()、update()將字段更新為null,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
      2022-08-08
    • spring mvc實(shí)現(xiàn)登錄賬號(hào)單瀏覽器登錄

      spring mvc實(shí)現(xiàn)登錄賬號(hào)單瀏覽器登錄

      這篇文章主要為大家詳細(xì)介紹了spring mvc實(shí)現(xiàn)登錄賬號(hào)單瀏覽器登錄,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
      2017-04-04
    • Spring中基于xml的AOP的詳細(xì)步驟

      Spring中基于xml的AOP的詳細(xì)步驟

      這篇文章主要介紹了Spring中基于xml的AOP的詳細(xì)步驟,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
      2020-06-06
    • 詳解Java內(nèi)存管理中的JVM垃圾回收

      詳解Java內(nèi)存管理中的JVM垃圾回收

      這篇文章給大家分享了關(guān)于Java內(nèi)存管理中的JVM垃圾回收的相關(guān)知識(shí)點(diǎn)內(nèi)容,有興趣的朋友們可以學(xué)習(xí)參考下。
      2018-08-08
    • Java8實(shí)現(xiàn)任意參數(shù)的鏈棧

      Java8實(shí)現(xiàn)任意參數(shù)的鏈棧

      這篇文章主要為大家詳細(xì)介紹了Java8實(shí)現(xiàn)任意參數(shù)的鏈棧,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
      2020-10-10
    • 布隆過濾器(Bloom Filter)的Java實(shí)現(xiàn)方法

      布隆過濾器(Bloom Filter)的Java實(shí)現(xiàn)方法

      下面小編就為大家?guī)硪黄悸∵^濾器(Bloom Filter)的Java實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
      2016-12-12
    • SpringBoot模板引擎之Thymeleaf的使用

      SpringBoot模板引擎之Thymeleaf的使用

      這篇文章主要介紹了SpringBoot模板引擎之Thymeleaf的使用,模板引擎是以業(yè)務(wù)邏輯層和表現(xiàn)層分離為目的的,將規(guī)定格式的模板代碼轉(zhuǎn)換為業(yè)務(wù)數(shù)據(jù)的算法實(shí)現(xiàn),它可以是一個(gè)過程代碼、一個(gè)類,甚至是一個(gè)類庫,需要的朋友可以參考下
      2023-10-10
    • SpringBoot獲取http數(shù)據(jù)、打印HTTP參數(shù)的4種方式

      SpringBoot獲取http數(shù)據(jù)、打印HTTP參數(shù)的4種方式

      Java的話本地打斷點(diǎn)可以調(diào)試獲取rest入?yún)?但是在生產(chǎn)環(huán)境可能我們獲取入?yún)ⅲ℉ttp?header/parameter)可能就沒有那么的輕松了,所以本文給大家介紹了SpringBoot獲取http數(shù)據(jù)、打印HTTP參數(shù)的4種方式,需要的朋友可以參考下
      2024-03-03
    • Java split()方法中的特殊符號(hào)舉例詳解

      Java split()方法中的特殊符號(hào)舉例詳解

      Java中的split方法可以將一個(gè)字符串按照指定的分隔符進(jìn)行分割,返回一個(gè)字符串?dāng)?shù)組,這篇文章主要給大家介紹了關(guān)于Java split()方法中的特殊符號(hào)的相關(guān)資料,需要的朋友可以參考下
      2023-07-07
    • Idea如何配置Maven才能優(yōu)先從本地倉庫獲取依賴(親測(cè)方法有效)

      Idea如何配置Maven才能優(yōu)先從本地倉庫獲取依賴(親測(cè)方法有效)

      對(duì)于Idea怎么配置Maven才能優(yōu)先從本地倉庫獲取依賴,網(wǎng)上說法有很多種,都不太靠譜,最終都沒有效果,最好的解決方法是通過修改maven配置文件settings.xml,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧
      2023-10-10

    最新評(píng)論