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

java編寫全年考勤日歷

 更新時(shí)間:2018年11月29日 12:04:04   作者:始于千里之外  
這篇文章主要為大家詳細(xì)介紹了java編寫全年考勤日歷,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java編寫全年考勤日歷的具體代碼,供大家參考,具體內(nèi)容如下

JAVA代碼:

package com.wp.action;
 
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
 
public class CalendarAction extends MainAction {
 
 private static final long serialVersionUID = 1L;
 
 private int maxCols;
 private String html;
 private String clickDate;
 
 public String getClickDate() {
 return clickDate;
 }
 
 public void setClickDate(String clickDate) {
 this.clickDate = clickDate;
 }
 
 public String init() {
 Calendar cal = Calendar.getInstance();
 int month = cal.get(Calendar.MONTH) + 1;
 initMaxCols();
 html = createTbl();
 
 return SUCCESS;
 }
 
 private void initMaxCols() {
 // 每行開頭灰色的格數(shù)
 int headDisabledDays;
 // 當(dāng)月的天數(shù)
 int oneMonthDays;
 Calendar cal = Calendar.getInstance();
 cal.set(Calendar.DAY_OF_MONTH, 1);
 
 for (int i = 0; i < 12; i++) {
 
  if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
  // 周日空六格
  headDisabledDays = 6;
  } else {
  headDisabledDays = cal.get(Calendar.DAY_OF_WEEK)
   - Calendar.MONDAY;
  }
 
  oneMonthDays = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
  if (headDisabledDays + oneMonthDays > maxCols) {
  maxCols = headDisabledDays + oneMonthDays;
  }
  cal.add(Calendar.MONTH, 1);
 }
 
 }
 
 private String createTbl() {
 StringBuffer html = new StringBuffer();
 String[] weekdays = { "一", "二", "三", "四", "五", "六", "日" };
 SimpleDateFormat formatTd = new SimpleDateFormat("yyyyMMdd");
 SimpleDateFormat formatHeader = new SimpleDateFormat("yyyy年MM月");
 SimpleDateFormat formatTitle = new SimpleDateFormat("yyyy年MM月dd日");
 HashMap<String, String> map = getCalendarDetail();
 
 // 每行開頭灰色的格數(shù)
 int headDisabledDays;
 
 // html.append("<table id='calTbl'>\r\n");
 html.append("<tr>\r\n");
 html.append("<th></th>\r\n");
 for (int col = 0; col < maxCols; col++) {
  html.append("<th>");
  html.append(weekdays[col % weekdays.length]);
  html.append("</th>\r\n");
 }
 html.append("</tr>\r\n");
 Calendar cal = Calendar.getInstance();
 int month = cal.get(Calendar.MONTH);
 for (int months = 0; months < 12; months++) {
  html.append("<tr>\r\n");
  String s;
  s = formatHeader.format(cal.getTime());
  html.append("<td class='rowHeader'>" + s + "</td>\r\n");
  
  cal.set(Calendar.DAY_OF_MONTH, 1);
  if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
  // 周日空六格
  headDisabledDays = 6;
  } else {
  headDisabledDays = cal.get(Calendar.DAY_OF_WEEK)
   - Calendar.MONDAY;
  }
  cal.add(Calendar.DAY_OF_MONTH, -headDisabledDays);
 
  for (int col = 0; col < maxCols; col++) {
 
  html.append("<td id='");
 
  String date = formatTd.format(cal.getTime());
  html.append(date + "' ");
  // if (headDisabledDays-- > 0) {
  // html.append("class='disabledTd'");
  // }else
  if (month != cal.get(Calendar.MONTH)) {
   html.append("class='disabledTd'");
  
  } else if (map.containsKey(formatTd.format(cal.getTime()))) {
   int type = Integer.parseInt(map.get(formatTd.format(cal
    .getTime())));
   if(type == 1){
   //html.append("class='holidayTd'");
   }else if(type == 2){
   html.append("class='holidayTd'");
   }
  } else if (cal.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY
   || cal.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
   html.append("class='weekendTd'");
  } else {
   html.append("class='generalTd'");
  }
  html.append(" title='" + formatTitle.format(cal.getTime())
   + "'");
  html.append(">");
 
  html.append(cal.get(Calendar.DAY_OF_MONTH));
  html.append("</td>\r\n");
  cal.add(Calendar.DAY_OF_MONTH, 1);
 
  }
 
  html.append("</tr>\r\n");
  if (month == cal.get(Calendar.MONTH)) {
  cal.add(Calendar.MONTH, 1);
  }
  month = cal.get(Calendar.MONTH);
 }
 // html.append("</table>\r\n");
 return html.toString();
 }
 
 public String getHtml() {
 return html;
 }
 
 public void setHtml(String html) {
 this.html = html;
 }
 
 private HashMap<String, String> getCalendarDetail() {
 HashMap<String, String> map;
 map = new HashMap<String, String>();
 map.put("20150404", "2");
 map.put("20150405", "2");
 map.put("20150406", "2");
 map.put("20150501", "2");
 map.put("20150502", "2");
 map.put("20150503", "2");
 map.put("20150622", "2");
 map.put("20151001", "2");
 map.put("20151002", "2");
 map.put("20151003", "2");
 
 return map;
 }
 public String dateCellClick(){
 
 return SUCCESS;
 }
}

action配置:

<action name="calendar" class="com.wp.action.CalendarAction" method="init">
   <result name="success" type="json"></result>
</action>

HTML代碼:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=utf-8"
 pageEncoding="utf-8"%>
<%
 String path = request.getContextPath();
 String basePath = request.getScheme() + "://"
  + request.getServerName() + ":" + request.getServerPort()
  + path;
%>
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
 <STYLE type="text/css">
  .disabledTd{
  background-color:gray;
  }
  .weekendTd{
  background-color:yellow;
  }
  .holidayTd{
  background-color:green;
  }
  .generalTd{
  background-color:white;
  }
  #calTbl{
  font-family: verdana,arial,sans-serif;
  font-size:13px;
  color:#333333;
  border-width: 1px;
  border-color: #a9c6c9;
  border-collapse: collapse;
  }
  #calTbl th{
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #a9c6c9;
  background-color:olive;
  }
  #calTbl td {
  border-width: 1px;
  padding: 4px;
  border-style: solid;
  border-color: #a9c6c9;
  }
  .rowHeader{
  background-color:olive;
  }
 </STYLE>
 
 <head>
 
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Login page</title>
 <link rel="stylesheet" type="text/css" media="screen"
  href="<%=basePath%>/html/styles/styles.css" rel="external nofollow" />
 <script src="<%=basePath%>/html/scripts/common.js"
  type="text/javascript"></script>
 <script src="<%=basePath%>/html/scripts/jquery.js"
  type="text/javascript"></script>
 <script src="<%=basePath%>/html/scripts/jquery.json-2.2.min.js"
  type="text/javascript"></script>
 <script src="<%=basePath%>/html/scripts/jquery.ui.custom.js"
  type="text/javascript"></script>
 <script src="<%=basePath%>/html/scripts/script.js"
  type="text/javascript"></script>
  <script type="text/javascript">
  $(document).ready(function(){
  var checkType = 0;
  $.post('calendar',{},function(data,status)
  {
   if(data != null && data.html != null && data.html != ""){
   $("#calTbl").html( data.html);
   $("#calTbl td").click(tdClick);
   $("#checkType input").click(typeCheck);
   }
  }).error(function(){
   
  });
 
  var tdClick = function(){
  
   if(this.className == 'rowHeader' || this.className == 'disabledTd'){
   return;
   }
   if(checkType != null && checkType != "" && checkType != 0){
   if(checkType == 1){   
    this.style.backgroundColor="white";
   }else if(checkType == 2){    
    this.style.backgroundColor="yellow";
   }else if(checkType == 3){    
    this.style.backgroundColor="green";
   }
   }
  };
  var typeCheck = function(){
   checkType = this.value;
  };
  
  
  });
  
 </script>
 </head>
 <body>
 <div id="calendar">
  <table id="calTbl"></table>  
 </div>
 <div>
  <table id="checkType">
  <tr>
   <td style="background-color: white;"> <input type="radio" name="type" value="1"> </td>
   <td style="background-color: yellow;"><input type="radio" name="type" value="2"></td>
   <td style="background-color: green;"> <input type="radio" name="type" value="3"></td>
  </tr>
  </table>
 </div> 
 </body>
</html>

效果如下

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Java實(shí)現(xiàn)簡(jiǎn)單SPI流程

    詳解Java實(shí)現(xiàn)簡(jiǎn)單SPI流程

    這篇文章主要介紹了Java實(shí)現(xiàn)簡(jiǎn)單SPI流程,SPI英文全稱為Service Provider Interface,顧名思義,服務(wù)提供者接口,它是jdk提供給“服務(wù)提供廠商”或者“插件開發(fā)者”使用的接口
    2023-03-03
  • JWT整合Springboot的方法步驟

    JWT整合Springboot的方法步驟

    本文主要介紹了JWT整合Springboot的方法步驟,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-11-11
  • Java裝飾器設(shè)計(jì)模式_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    Java裝飾器設(shè)計(jì)模式_動(dòng)力節(jié)點(diǎn)Java學(xué)院整理

    這篇文章主要介紹了Java裝飾器設(shè)計(jì)模式的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-05-05
  • Quartz與Spring集成的兩種方法示例

    Quartz與Spring集成的兩種方法示例

    這篇文章主要為大家介紹了Quartz與Spring集成的兩種方法示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步早日升職加薪
    2022-04-04
  • 使用Springboot封裝一個(gè)自適配的數(shù)據(jù)單位轉(zhuǎn)換工具類

    使用Springboot封裝一個(gè)自適配的數(shù)據(jù)單位轉(zhuǎn)換工具類

    我們?cè)诮邮涨芭_(tái)傳輸?shù)臄?shù)據(jù)時(shí),往往SpringBoot使用內(nèi)置的數(shù)據(jù)類型轉(zhuǎn)換器把我們提交的數(shù)據(jù)自動(dòng)封裝成對(duì)象等類型,下面這篇文章主要給大家介紹了關(guān)于使用Springboot封裝一個(gè)自適配的數(shù)據(jù)單位轉(zhuǎn)換工具類的相關(guān)資料,需要的朋友可以參考下
    2023-03-03
  • Java 靜態(tài)數(shù)據(jù)初始化的示例代碼

    Java 靜態(tài)數(shù)據(jù)初始化的示例代碼

    這篇文章主要介紹了Java 靜態(tài)數(shù)據(jù)初始化的示例代碼,幫助大家更好的理解和學(xué)習(xí)Java,感興趣的朋友可以了解下
    2020-09-09
  • JDK環(huán)境變量配置教程分享

    JDK環(huán)境變量配置教程分享

    這篇文章主要為大家分享了JDK環(huán)境變量配置教程,JDK環(huán)境變量的配置,是java開發(fā)中必備的配置
    2016-05-05
  • Java使用嵌套循環(huán)模擬ATM機(jī)取款業(yè)務(wù)操作示例

    Java使用嵌套循環(huán)模擬ATM機(jī)取款業(yè)務(wù)操作示例

    這篇文章主要介紹了Java使用嵌套循環(huán)模擬ATM機(jī)取款業(yè)務(wù)操作,結(jié)合實(shí)例形式分析了Java模擬ATM機(jī)取款業(yè)務(wù)操作的相關(guān)流程控制、數(shù)值判斷等操作技巧,需要的朋友可以參考下
    2019-11-11
  • Java JVM調(diào)優(yōu)五大技能詳解

    Java JVM調(diào)優(yōu)五大技能詳解

    這篇文章主要為大家介紹了JVM調(diào)優(yōu)的五大技能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來(lái)幫助
    2021-11-11
  • JAVA字符串拼接常見方法匯總

    JAVA字符串拼接常見方法匯總

    這篇文章主要介紹了JAVA字符串拼接常見方法,文中講解非常細(xì)致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-06-06

最新評(píng)論