一个用java作的日历的源代码

2016-02-19 15:35 37 1 收藏

下面请跟着图老师小编一起来了解下一个用java作的日历的源代码,精心挑选的内容希望大家喜欢,不要忘记点个赞哦!

【 tulaoshi.com - 编程语言 】

  

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;i49;i++)
{
days[i]=new Button("");
}
for(int c=0;c49;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 ( myday0)
{
int blank= myday;
for( ;blank0;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);
}
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

来源:https://www.tulaoshi.com/n/20160219/1609974.html

延伸阅读
//保存文件的路径,包括文件名 private string GetSavePath(string FileName) { string path=Request.PhysicalApplicationPath +"\\Link_Icon"; return path+"\\"+FileName; } private bool UpLoad()//上传图片 { bool flag=false; string FileName=GetFileName(fileIcon.Value ); string db=Request.PhysicalApplicationP...
标签: Java JAVA基础
在现代的操作系统中,有一个很重要的概念――线程,几乎所有目前流行的操作系统都支持线程,线程来源于操作系统中进程的概念,进程有自己的虚拟地址空间以及正文段、数据段及堆栈,而且各自占有不同的系统资源(例如文件、环境变量等等)。与此不同,线程不能单独存在,它依附于进程,只能由进程派生。如果一个进程派生出了两个...
界面是防明小子的那个扫描工具写的,算是学习多线程的一个例子把 界面图示: http://www.wrsky.com/attachment/3_1875.jpg 程序和源代码: http://downloads.2ccc.com/general/internet_lan/hnxyy_scan.rar 使用D7编写,主要部分代码: //主界面部分 unit1.pas unit...
标签: Web开发
一个可以找出源代码中所有中文的工具 填写需要查找的路径$sf即可。 功能 1 找出所有中文 2 忽略注释语句中的中文 3 可添加需要忽略的文件和文件夹 4 生成日志文件 如果您正发愁为自己的软件更新语言包 请使用此工具。 我的例子: http://127.0.0.1/tools/searchcn.php http://127.0.0.1/tools/cnlog.txt 代...
using System; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; namespace wzsbmain {  /// <summary  /// Summary description for LabelGradient.  /// </summary     public class wzsbmainLabel : System.Windows.Forms.Label &nbs...

经验教程

208

收藏

30
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部