欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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中放置一個標簽用來顯示一些信息。請完成界面設計和相關(guān)功能。運行結(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)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • spring boot mogodb多條件拼接的解決方法

    spring boot mogodb多條件拼接的解決方法

    這篇文章主要介紹了spring boot mogodb多條件拼接的解決方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2018-08-08
  • Spring?Data?Jpa框架最佳實踐示例

    Spring?Data?Jpa框架最佳實踐示例

    這篇文章主要為大家介紹了Spring?Data?Jpa框架最佳實踐示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步早日升職加薪
    2022-02-02
  • javap命令的使用技巧

    javap命令的使用技巧

    本篇文章給大家分享了關(guān)于JAVA中關(guān)于javap命令的使用技巧以及相關(guān)代碼分享,有需要的朋友參考學習下。
    2018-05-05
  • Springboot項目對數(shù)據(jù)庫用戶名密碼實現(xiàn)加密過程解析

    Springboot項目對數(shù)據(jù)庫用戶名密碼實現(xiàn)加密過程解析

    這篇文章主要介紹了Springboot項目對數(shù)據(jù)庫用戶名密碼實現(xiàn)加密過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-06-06
  • 不知道面試會不會問Lambda怎么用(推薦)

    不知道面試會不會問Lambda怎么用(推薦)

    這篇文章主要介紹了Lambda表達式用法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-04-04
  • java使用@Transactional時常犯的N種錯誤

    java使用@Transactional時常犯的N種錯誤

    @Transactional是我們在用Spring時候幾乎逃不掉的一個注解,本文主要介紹了使用?@Transactional?時常犯的N種錯誤,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-01-01
  • Redis實現(xiàn)延遲隊列的全流程詳解

    Redis實現(xiàn)延遲隊列的全流程詳解

    Redisson是Redis服務器上的分布式可伸縮Java數(shù)據(jù)結(jié)構(gòu),這篇文中主要為大家介紹了Redisson實現(xiàn)的優(yōu)雅的延遲隊列的方法,需要的可以參考一下
    2023-03-03
  • Mybatis配置之typeAlias標簽的用法

    Mybatis配置之typeAlias標簽的用法

    這篇文章主要介紹了Mybatis配置之typeAlias標簽的用法,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2021-07-07
  • java中成員變量與局部變量區(qū)別分析

    java中成員變量與局部變量區(qū)別分析

    這篇文章主要介紹了java中成員變量與局部變量區(qū)別,較為詳細的分析了java中成員變量與局部變量的功能、用法與區(qū)別,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-01-01
  • Spring 中使用Quartz實現(xiàn)任務調(diào)度

    Spring 中使用Quartz實現(xiàn)任務調(diào)度

    這篇文章主要介紹了Spring 中使用Quartz實現(xiàn)任務調(diào)度,Spring中使用Quartz 有兩種方式,感興趣的小伙伴們可以參考一下。
    2017-02-02

最新評論