⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 java日历1.txt

📁 聊天室 躬耕还行 自己试试就知道 谁用谁知道
💻 TXT
字号:
 
 
import java.awt.*; 

import java.awt.event.*; 


import java.util.*; 





public class CalenderCreator extends Frame 


{ 


Button days[]=new Button[49]; 


Choice Month=new Choice(); 


Choice Year=new Choice(); 


Label lmonth=new Label("MONTH"); 


Label lyear=new Label("Year"); 


Label ltext=new Label("YEAR UPTO:::"); 


Panel p1,p2; 


GregorianCalendar gc=new GregorianCalendar(); 


int totdays; 


TextField textfield=new TextField(2); 








public CalenderCreator() 


{ 


setTitle("This is a calender"); 


setSize(400,400); 


setResizable(false); 


setLocation(50,50); 


p1=new Panel(new FlowLayout()); 


p2=new Panel(new GridLayout(7,7,10,10)); 


p1.setBackground(Color.red); 


p2.setBackground(Color.cyan); 


add(p1,BorderLayout.NORTH); 


add(p2); 





p1.add(ltext); 


p1.add(textfield); 


p1.add(lmonth); 


p1.add(Month); 


Month.add("JAN"); 


Month.add("FEB"); 


Month.add("MAR"); 


Month.add("APR"); 


Month.add("MAY"); 


Month.add("JUN"); 


Month.add("JUL"); 


Month.add("AUG"); 


Month.add("SEP"); 


Month.add("OCT"); 


Month.add("NOV"); 


Month.add("DEC"); 


Month.addItemListener(new myLis(this)); 


// int i1=myAction.newyear; // 


// System.out.println("iiiiiiiiii is :::::::"+i1); // 


textfield.addActionListener(new myAction(this)); // 








p1.add(lyear); 


p1.add(Year); 


Year.add("1990"); 


/* Year.add("1991"); 


Year.add("1992"); 


Year.add("1993"); 


Year.add("1994"); 


Year.add("1995"); */ 


Year.addItemListener(new myLis(this)); 





for(int i=0;i<49;i++) 


{ 


days[i]=new Button(""); 


} 





for(int c=0;c<49;c++) 


{ 


p2.add(days[c]); 


} 


setVisible(true); 


} 


void setYear(String mynewyear) 


{ 


int h=Integer.parseInt(mynewyear); 


for(int adder=1991;adder<=h;adder++) 


{ 


Year.add(""+adder); 


} 


} 


void setButtons(int myday,int mytotdays) 


{ 


int count=7; 





days[0].setLabel("SUN"); 


days[1].setLabel("MON"); 


days[2].setLabel("TUE"); 


days[3].setLabel("WED"); 


days[4].setLabel("THUR"); 


days[5].setLabel("FRI"); 


days[6].setLabel("SAT"); 





if ( myday>0) 


{ 


int blank= myday; 


for( ;blank>0;blank--,count++) 


{ 


days[count].setLabel(""); 


} 


} 


for(int i=1;i<=mytotdays; i++,count++) 


{ 


days[count].setLabel(""+i); 


} 


for(int j = 1;count < 49; j++,count++) 


{ 


days[count].setLabel(""); 


} 


} 





void setVal(Date date,int iday,int iselMonth,int iselYear) 


{ 


gc.setTime(date); 


if(iselMonth==0 || iselMonth==2 || iselMonth==4 || iselMonth==6 || iselMonth== 7 ||iselMonth==9 || iselMonth==11) 


{ 


totdays=31; 


setButtons(iday,totdays); 


} 





if(iselMonth==3 || iselMonth==5 || iselMonth==8 || iselMonth==10) 


{ 


totdays=30; 


setButtons(iday,totdays); 


} 





if(gc.isLeapYear(iselYear) && iselMonth==1) 


{ 


totdays=29; 


setButtons(iday,totdays); 


} 


if( !gc.isLeapYear(iselYear) && iselMonth==1) 


{ 


totdays=28; 


setButtons(iday,totdays); 


} 





} 





static public void main(String args[]) 


{ 


CalenderCreator c=new CalenderCreator(); 


} 


} 


class myLis implements ItemListener 


{ 


CalenderCreator calLis; 


public myLis(CalenderCreator c) 


{ 


calLis=c; 


} 


public void itemStateChanged(ItemEvent i) 


{ 


int selMonth=calLis.Month.getSelectedIndex(); 


int selYear1=Integer.parseInt(calLis.Year.getSelectedItem()); 


int selYear = selYear1- 1900; 


Date d1 = new Date(selYear,selMonth,1); 


int day = d1.getDay(); 


calLis.setVal(d1,day,selMonth,selYear); 


} 


} 


class myAction implements ActionListener 


{ 


CalenderCreator calAc; 


int newyear; 





public myAction(CalenderCreator ca) 


{ 


calAc=ca; 


} 


public void actionPerformed(ActionEvent e) 


{ 


String s=calAc.textfield.getText(); 


// newyear=Integer.parseInt(s); 


System.out.println("Year upto::::::::"+s); 


calAc.setYear(s); 


TextField tf = (TextField)e.getSource(); 


tf.removeActionListener(this); 


} 


} 








代码下载 








代码名称 一个登陆验证码  版 本 1.0 


代码分类 SERVLET 


整理日期 2003-04-23 09:40:54  


文件大小 2 KB 


代码作者 falcon  


下载次数 1218 


代码内容 由于做网站需要写了一个,感觉大家可能用的着 


调用方法 (作者falcon 来自JAVA-CN.COM 论坛) 


<img src="http://...../getImg"> 





原理,在servlet中随机生成一个4位数字1000-9999 


然后把这数字写入session 


输出一个图片,上面写有这四个数字 


在服务器端根据用户输入的数字和 


session中的值比较。 








package com.schoolwx.util; 


import java.io.*; 


import java.util.*; 


import com.sun.image.codec.jpeg.*; 


import javax.servlet.*; 


import javax.servlet.http.*; 


import java.awt.*; 


import java.awt.image.*; 








/** 


* Title: getImg.java 


* Description: 这个class主要实现随机生成一个4位数的验证码,并写入session, 


* Copyright: Copyright (c) 2003 


* Company: 蓝星软件 


* @author falcon 


* @version 1.1 


*/ 








public class getImg extends HttpServlet { 





private Font mFont=new Font("宋体", Font.PLAIN,12);//设置字体 


//处理post 


public void doPost(HttpServletRequest request,HttpServletResponse response) 


throws ServletException,IOException { 





doGet(request,response); 


} 


public void doGet(HttpServletRequest request,HttpServletResponse response) 


throws ServletException,IOException { 


//取得一个1000-9999的随机数 


String s=""; 





int intCount=0; 





intCount=(new Random()).nextInt(9999);// 





if(intCount<1000)intCount+=1000; 





s=intCount+""; 








//对session付值。 





HttpSession session=request.getSession (true); 





session.setAttribute("getImg",s); 





response.setContentType("image/gif"); 





ServletOutputStream out=response.getOutputStream(); 





BufferedImage image=new BufferedImage(35,14,BufferedImage.TYPE_INT_RGB); 





Graphics gra=image.getGraphics(); 


//设置背景色 


gra.setColor(Color.yellow); 





gra.fillRect(1,1,33,12); 


//设置字体色 


gra.setColor(Color.black); 





gra.setFont(mFont); 


//输出数字 


char c; 





for(int i=0;i<4;i++) { 





c=s.charAt(i); 





gra.drawString(c+"",i*7+4,11); //7为宽度,11为上下高度位置 





} 





JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(out); 





encoder.encode(image); 





out.close(); 





 } 

} 


  
 
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -