java 和历_Java 布局与日历

这是一个使用Java Applet创建日历的示例。代码中定义了一个名为Boy的类,该类继承自Applet并实现了ActionListener接口。程序通过GridLayout和BorderLayout布局管理器来组织组件,包括星期标题、日期标签以及前进和后退按钮。日历显示的年份为2005年,月份可设置。点击按钮可以切换月份。
摘要由CSDN通过智能技术生成

//boy.javaimportjava.util.*;importjava.awt.*;importjava.awt.event.*;importjava.applet.*;publicclassBoyextendsAppletimplementsActionListener{Labela[]=newLabel[42];Buttonti...

//boy.java

import java.util.*;

import java.awt.*;

import java.awt.event.*;

import java.applet.*;

public class Boy extends Applet implements ActionListener

{

Label a[]=new Label[42];

Button titleName[]=new Button[7];

String name[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

Button nextMonth,previousMonth;

int i,year=2005,month=1;

CalendarBean calendar;

Laber showMessage=new Label("",Label.center);

Public void main()

{

super ("小程序查看器:Boy.class");

int hgap=5,vap=5;

setLayout(new BorderLayout(5,5));

//[代码1]将Java Applet的布局设置为BorderLayout布局

Panel pCenter=new Panel();

pCenter.setLayout(new GridLayout(7,7));

//[代码2]将pCenter的布局设置为7行7列的GridLayout布局

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

{

titleName[i]=new Button(name[i]);

pCenter.add(new Button(titleName[i]));

// [代码3] pCenter添加组件titleName[i]

}

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

{

a[i]=new Label(" ",Label.CENTER);

pCenter.add(new Button(a[i]));

//[代码3]pCenter添加组件a[i]

}

Calendar=new CalendarBean();

year=2005;

calendar.setYear(year);

calendar.setMonth(month);

String day[]=calendar.getCalendar();

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

{

a[i].setText(day[i]);

}

nextMonth=new Button("下月");

nextMonth.addActionListener(this);

Panel pNorth=new Panel();

pSorth=new Panel();

pNorth.add(previousMonth);

pNorth.add(nextMonth);

pSorth.add(showMessage);

showMessage.setText("日历:"+calendar.getYear()+"年"+calendar.getMonth()+"月");

ScrollPane scrollPane=new ScrollPane();

scrollPane.add(pCenter);

BtnC=new Button(scrollPane);

add (scrollPane,Btnc);

//[代码5]将Java Applet添加scrollPane在中心区域

BtnN=new Button(pNorth);

add (pNorth,Btnc);

//[代码6]将Java Applet添加pMonth在中心区域

BtnS=new Button(pSouth);

add (pSouth,BtnS);

//[代码7]将Java Applet添加pSouth在中心区域

}

后面还有接着的。。帮我看看拿哪错了

展开

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值