📄 java rl.txt
字号:
import java.awt.*;
import java.awt.event.*;
import java.util.*;
//创建组类
public class cc extends Frame
{
//建造界面
Button days[]=new Button[49];
Choice Month=new Choice();
Choice Year=new Choice();
Label zz=new Label("王利军:韩立兆");
Label lmonth=new Label("MONTH");
Label lyear=new Label("Year");
Panel p1,p2;
GregorianCalendar gc=new GregorianCalendar();
int totdays;
//设置标题大小及位置
public cc()
{long p,q,r;
Date d=new Date();
p=d.getYear()+1900;
q=d.getMonth()+1;
r=d.getDate();
setTitle("日历:"+p+"年"+q+"月"+r+"日");
setSize(350,320);
setResizable(true);
setLocation(150,150);
p1=new Panel(new FlowLayout());
p2=new Panel(new GridLayout(7,7,10,10));
p1.setBackground(Color.blue);
p2.setBackground(Color.cyan);
add(p1,BorderLayout.NORTH);
add(p2);
p1.add(zz);
//添加月份并加载到窗体
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 myl(this));
addWindowListener(new lis());
//添加年份并加载到窗体
p1.add(lyear);
p1.add(Year);
Year.add("2007");
Year.add("2006");
Year.add("2005");
Year.add("2004");
Year.add("2003");
Year.add("2002");
Year.add("2001");
Year.add("2000");
Year.add("1987");
Year.add("1986");
Year.add("1985");
Year.addItemListener(new myl(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 nyear)
{
int h=Integer.parseInt(nyear);
for(int adder=1980;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("THU");
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("");
}
}
//设置一、三、五、七、八、十、十二月(31天)的显示方法
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);
}
//设置四、六、九、十一月(30天)的显示方法
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[])
{
cc c=new cc();
}
}
class myl implements ItemListener
{
cc calLis;
public myl(cc 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);
}
}
//WINDOWS窗口按钮的加载
class lis extends WindowAdapter{
public void windowClosing(WindowEvent e){
System.exit(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -