最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Java實現(xiàn)桌面日歷

 更新時間:2022年06月13日 11:47:35   作者:行秋  
這篇文章主要為大家詳細介紹了Java實現(xiàn)桌面日歷,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了Java實現(xiàn)桌面日歷的具體代碼,供大家參考,具體內(nèi)容如下

問題描述:

編寫一個程序,有一個窗口,該窗口為BorderLayout布局。窗口的中心添加一個Panel容器:pCenter,pCenter的布局是7行7列的GridLayout布局,pCenter的中放置49個標簽,用來顯示日歷。窗口北面添加一個Panel容器pNorth,其布局是FlowLayout布局,pNorth放置兩個按鈕:nextMonth和previousMonth按鈕,單擊nextMonth,可以顯示當前月的下一個月的日歷;單擊previousMonth按鈕,可以顯示當前月的上一個月的日歷。窗口的南面添加一個Panel容器pSouth,其布局是FlowLayout布局,pSouth中放置一個標簽用來顯示一些信息。請完成界面設計和相關功能。運行結(jié)果如下圖所示。

問題解決:

新建Java項目,在項目下新建package,命名為Calendar。

CalendarBean.java

package Calendar;
?
import java.util.Calendar;
public class CalendarBean
{?
? String ?day[];
? int year=2018,month=0;
? public void setYear(int year)
? { ? ?
?? ? ?this.year=year;
? }
? public int getYear()
? { ??
? ? ? return year;
? }
? public void setMonth(int month)
? { ? ?
?? ? ?this.month=month;
? }
? public int getMonth()
? { ? ?
?? ? ?return month;
? }
? public String[] getCalendar()
? { ? String a[]=new String[42]; ? ?
? ? ? Calendar 日歷=Calendar.getInstance();
? ? ? 日歷.set(year,month-1,1); ? ? ? ? ? ?
? ? ? int 星期幾=日歷.get(Calendar.DAY_OF_WEEK)-1;
? ? ? int day=0;
? ? ?if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
? ? ? { ?
? ? ?? ? day=31;
? ? ? }
? ? if(month==4||month==6||month==9||month==11)
? ? ? { ?
? ? ?? ?day=30;
? ? ? }
? ? if(month==2)
? ? ?{ ?if(((year%4==0)&&(year%100!=0))||(year%400==0))
? ? ? ? ? { ??
? ? ?? ? day=29;
? ? ? ? ? }
? ? ? ? else
? ? ? ? ? { ??
? ? ? ? ?? ?day=28;
? ? ? ? ? }
? ? ?}
? ? for(int i=星期幾,n=1;i<星期幾+day;i++)
? ? ?{
? ? ? ? a[i]=String.valueOf(n) ;
? ? ? ? n++;
? ? ?}?
? ? ?return a;
? }
}

CalendarFrame.java

package Calendar;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class CalendarFrame extends Frame implements ActionListener
{ ? ?
?? ?Label labelDay[]=new Label[42];
? ? ?Button titleName[]=new Button[7];
? ? ?String name[]={"日","一","二","三", "四","五","六"};
? ? ?Button nextMonth,previousMonth;
? ? ?int year=2020,month=5;
? ? ?CalendarBean calendar;
? ? ?Label showMessage=new Label("",Label.CENTER);
? ? ?public CalendarFrame()
? ? ?{ ?Panel pCenter=new Panel();
? ? ? ?pCenter.setLayout(new GridLayout(7,7)); //將pCenter的布局設置為7行7列的GridLayout 布局。
? ? ? ? for(int i=0;i<7;i++)
? ? ? ? { ?
? ? ? ? ?? ?titleName[i]=new Button(name[i]);
? ? ? ? ? ? pCenter.add(titleName[i]);//pCenter添加組件titleName[i]。
? ? ? ? }
? ? ? ? for(int i=0;i<42;i++)
? ? ? ? {
? ? ? ? ? ?labelDay[i]=new Label("",Label.CENTER);
? ? ? ? ? ?pCenter.add(labelDay[i]);//pCenter添加組件labelDay[i]。
? ? ? ? }
? ? ? ? calendar=new ?CalendarBean();
? ? ? ? calendar.setYear(year);
? ? ? ? calendar.setMonth(month);
? ? ? ? String day[]=calendar.getCalendar();
? ? ? ? for(int i=0;i<42;i++)
? ? ? ? { ?
? ? ? ? ?? ?labelDay[i].setText(day[i]);
? ? ? ? }
? ? ? ? nextMonth=new Button("下月");
? ? ? ? previousMonth=new Button("上月");
? ? ? ? nextMonth.addActionListener(this);
? ? ? ? previousMonth.addActionListener(this);
? ? ? ? Panel pNorth=new Panel(),
? ? ? ? ? ? ? pSouth=new Panel();
? ? ? ? pNorth.add(previousMonth);
? ? ? ? pNorth.add(nextMonth);
? ? ? ? pSouth.add(showMessage);
? ? ? ? showMessage.setText("日歷:"+calendar.getYear()+"年"+ calendar.getMonth()+"月" );
? ? ? ? ScrollPane scrollPane=new ScrollPane();
? ? ? ? scrollPane.add(pCenter);
? ? ? ? add(scrollPane,BorderLayout.CENTER);// 窗口添加scrollPane在中心區(qū)域
? ? ? ? add(pNorth,BorderLayout.NORTH);// ?窗口添加pNorth 在北面區(qū)域
? ? ? ? add(pSouth,BorderLayout.SOUTH);// 窗口添加pSouth 在南區(qū)域。
? ? ?}
? ? ?public void actionPerformed(ActionEvent e)
? ? ?{ ?if(e.getSource()==nextMonth)
? ? ? ? { month=month+1;
? ? ? ? ? if(month>12) {
? ? ? ? ? ? ? month=1;
? ? ? ? ? ? ? year++;
? ? ? ? ? }
? ? ? ? ? calendar.setYear(year);
? ? ? ? ? calendar.setMonth(month);
? ? ? ? ? String day[]=calendar.getCalendar();
? ? ? ? ? for(int i=0;i<42;i++)
? ? ? ? ? ?{?
? ? ? ? ?? ? ?labelDay[i].setText(day[i]);
? ? ? ? ? ?}
? ? ? ? }
? ? ? ?else if(e.getSource()==previousMonth)
? ? ? ? { month=month-1;
? ? ? ? ?if(month<1) {
? ? ? ? ? ? ? month=12;
? ? ? ? ? ? ? year--;
? ? ? ? ?}
? ? ? ? ? calendar.setYear(year);
? ? ? ? ? calendar.setMonth(month);
? ? ? ? ? String day[]=calendar.getCalendar();
? ? ? ? ? ?for(int i=0;i<42;i++)
? ? ? ? ? ?{ ?
? ? ? ? ?? ? ? labelDay[i].setText(day[i]);
? ? ? ? ? ?}
? ? ? ? }
? ? ? ?showMessage.setText("日歷:"+calendar.getYear()+"年"+calendar.getMonth()+"月" );
? ? ?}
}

CalendarMainClass.java

package Calendar;
public class CalendarMainClass
{?
?? ?public static void main(String args[])
?{ ??
?? ?CalendarFrame frame=new CalendarFrame();
? ? ?frame.setBounds(100,100,360,300);
? ? ?frame.setVisible(true);
? ? ?frame.validate();
? ? ?frame.addWindowListener(new java.awt.event.WindowAdapter()
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ?public void windowClosing(java.awt.event.WindowEvent e)
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? { ?System.exit(0);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? );
?}
}

運行結(jié)果:

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • SpringBoot2.0整合jackson配置日期格式化和反序列化的實現(xiàn)

    SpringBoot2.0整合jackson配置日期格式化和反序列化的實現(xiàn)

    這篇文章主要介紹了SpringBoot2.0整合jackson配置日期格式化和反序列化的實現(xiàn),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-11-11
  • MyBatis獲取自動生成的(主)鍵值的方法

    MyBatis獲取自動生成的(主)鍵值的方法

    本文主要介紹了MyBatis獲取自動生成的(主)鍵值的方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-04-04
  • 手動部署java項目到k8s中的實現(xiàn)

    手動部署java項目到k8s中的實現(xiàn)

    本文主要介紹了手動部署java項目到k8s中的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-08-08
  • Springboot之restTemplate配置及使用方式

    Springboot之restTemplate配置及使用方式

    這篇文章主要介紹了Springboot之restTemplate配置及使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2025-04-04
  • ehcache開源緩存框架_動力節(jié)點Java學院整理

    ehcache開源緩存框架_動力節(jié)點Java學院整理

    Ehcache是現(xiàn)在最流行的純Java開源緩存框架,這篇文章主要介紹了ehcache框架的相關資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-07-07
  • Java實現(xiàn)雙向鏈表(兩個版本)

    Java實現(xiàn)雙向鏈表(兩個版本)

    這篇文章主要介紹了Java實現(xiàn)雙向鏈表(兩個版本)的相關資料,需要的朋友可以參考下
    2016-02-02
  • SpringBoot@Componet注解注入失敗的問題

    SpringBoot@Componet注解注入失敗的問題

    這篇文章主要介紹了SpringBoot@Componet注解注入失敗的問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2023-03-03
  • Java裝飾器設計模式初探

    Java裝飾器設計模式初探

    這篇文章主要為大家詳細介紹了Java裝飾器設計模式,感興趣的小伙伴們可以參考一下
    2016-09-09
  • springboot項目事務標簽驗證

    springboot項目事務標簽驗證

    本文主要介紹了springboot項目事務標簽驗證,文中通過示例代碼介紹的非常詳細,詳細的介紹了不加事務標簽和加事物標簽的使用,需要的朋友們下面隨著小編來一起學習學習吧
    2021-07-07
  • 使用Maven配置Spring的方法步驟

    使用Maven配置Spring的方法步驟

    這篇文章主要介紹了使用Maven配置Spring的方法步驟,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-04-04

最新評論

苗栗市| 涟源市| 南投市| 天长市| 沙雅县| 根河市| 朝阳区| 宁强县| 宣汉县| 监利县| 伊吾县| 许昌县| 林周县| 吉首市| 大石桥市| 海伦市| 共和县| 鱼台县| 江油市| 沁阳市| 伊川县| 江永县| 文登市| 宜兰市| 山丹县| 阿拉尔市| 沂南县| 麦盖提县| 高安市| 新平| 绥阳县| 慈溪市| 梁平县| 潞城市| 临沂市| 错那县| 大名县| 浙江省| 类乌齐县| 明星| 长兴县|