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

Java編寫(xiě)實(shí)現(xiàn)窗體程序顯示日歷

 更新時(shí)間:2022年06月13日 10:56:00   作者:秋刀山名魚(yú)、  
這篇文章主要為大家詳細(xì)介紹了Java編寫(xiě)實(shí)現(xiàn)窗體程序顯示日歷,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Java實(shí)現(xiàn)窗體程序顯示日歷的具體代碼,供大家參考,具體內(nèi)容如下

實(shí)訓(xùn)要求:

代碼:

Test類(lèi):

import java.awt.*; ?
import java.awt.event.*; ?
import javax.swing.*; ?
??
public class Test extends JFrame { ?
? ? JButton week1, week2, week3, week4, week5, week6, week7, next, pro; ?
? ? CalendaBean cb = new CalendaBean(); ?
? ? JLabel[] label; ?
? ? JLabel now; ?
??
? ? public static void main(String[] args) { ?
? ? ? ? Test frame = new Test(); ?
? ? ? ? frame.setBounds(650,300,550,550);?
? ? ? ? frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ?
? ? ? ? frame.setTitle("日歷"); ?
? ? ? ? frame.setVisible(true); ?
??
? ? } ?
??
? ? public Test() { ?
? ? ? ? int year, month; ?
? ? ? ? setLayout(new BorderLayout()); ?
? ? ? ? JPanel pNorth = new JPanel(); ?
? ? ? ? cb = new CalendaBean(); ?
? ? ? ? cb.setYear(2017); ?
? ? ? ? cb.setMonth(11); ?
? ? ? ? String[] a = cb.getCalendar(); ?
? ? ? ? next = new JButton("上月"); ?
? ? ? ? pro = new JButton("下月"); ?
? ? ? ? next.setActionCommand("lastmonth"); ?
? ? ? ? pro.setActionCommand("nextmonth"); ?
? ? ? ? next.addActionListener(new ActionListener() { ?
? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ?
? ? ? ? ? ? ? ? cb.actionPerformed(e); ?
? ? ? ? ? ? } ?
? ? ? ? }); ?
? ? ? ? pro.addActionListener(new ActionListener() { ?
? ? ? ? ? ? public void actionPerformed(ActionEvent e) { ?
? ? ? ? ? ? ? ? cb.actionPerformed(e); ?
? ? ? ? ? ? } ?
? ? ? ? }); ?
? ? ? ? pNorth.add(next); ?
? ? ? ? pNorth.add(pro); ?
? ? ? ? add(pNorth, BorderLayout.NORTH); ?
? ? ? ? GridLayout grid = new GridLayout(8, 7); ?
? ? ? ? JPanel pCenter = new JPanel(); ?
? ? ? ? week1 = new JButton("日"); ?
? ? ? ? week2 = new JButton("一"); ?
? ? ? ? week3 = new JButton("二"); ?
? ? ? ? week4 = new JButton("三"); ?
? ? ? ? week5 = new JButton("四"); ?
? ? ? ? week6 = new JButton("五"); ?
? ? ? ? week7 = new JButton("六"); ?
? ? ? ? pCenter.add(week1); ?
? ? ? ? pCenter.add(week2); ?
? ? ? ? pCenter.add(week3); ?
? ? ? ? pCenter.add(week4); ?
? ? ? ? pCenter.add(week5); ?
? ? ? ? pCenter.add(week6); ?
? ? ? ? pCenter.add(week7); ?
? ? ? ? label = new JLabel[42]; ?
? ? ? ? for (int i = 0; i < 42; i++) { ?
? ? ? ? ? ? label[i] = new JLabel(); ?
? ? ? ? ? ? pCenter.add(label[i]); ?
? ? ? ? } ?
? ? ? ? cb.label = this.label; ?
? ? ? ? for (int i = 0; i < a.length; i++) { ?
? ? ? ? ? ? if (i % 7 == 0) { ?
? ? ? ? ? ? ? ? label[i].setText(""); ?
? ? ? ? ? ? } ?
? ? ? ? ? ? label[i].setText(" ? ? ? ? ?"+a[i]); ?
? ? ? ? } ?
? ? ? ? pCenter.setLayout(grid); ?
? ? ? ? add(pCenter, BorderLayout.CENTER); ?
? ? ? ? JPanel pSouth = new JPanel(); ?
? ? ? ? now = new JLabel(); ?
? ? ? ? now.setText("日歷:" + cb.year + "年" + cb.month + "月"); ?
? ? ? ? cb.now = now; ?
? ? ? ? pSouth.add(now); ?
? ? ? ? add(pSouth, BorderLayout.SOUTH); ?
? ? } ?
??
}?

CalendaBean類(lèi):

import java.awt.event.ActionEvent; ?
import java.awt.event.ActionListener; ?
import java.util.Calendar; ?
??
import javax.swing.*; ?
public class CalendaBean implements ActionListener { ?
? ? JLabel[] label; ?
? ? JLabel now; ?
? ? String[] day; ?
? ? int year = 0, month = 0; ?
? ? public void setYear(int year) { ?
? ? ? ? this.year = year; ?
? ? } ?
??
? ? public void setMonth(int month) { ?
? ? ? ? this.month = month; ?
? ? } ?
??
? ? public void actionPerformed(ActionEvent e) { ?
? ? ? ? String str = e.getActionCommand(); ?
? ? ? ? if (str.equals("lastmonth")) { ?
? ? ? ? ? ? month--; ?
? ? ? ? ? ? if (month == 0) { ?
? ? ? ? ? ? ? ? month = 12; ?
? ? ? ? ? ? ? ? year--; ?
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? ? ? else if (str.equals("nextmonth")) { ?
? ? ? ? ? ? month++; ?
? ? ? ? ? ? if (month == 13) { ?
? ? ? ? ? ? ? ? month = 1; ?
? ? ? ? ? ? ? ? year++; ?
? ? ? ? ? ? } ?
? ? ? ? } ?
? ? ? ? now.setText("日歷:" + year + "年" + month + "月"); ?
? ? ? ? String[] a = getCalendar(); ?
? ? ? ? for (int i = 0; i < a.length; i++) { ?
? ? ? ? ? ? if (i % 7 == 0) { ?
? ? ? ? ? ? ? ? label[i].setText(""); ?
? ? ? ? ? ? } ?
? ? ? ? ? ? label[i].setText(" ? ? ? ? ?"+a[i]); ?
? ? ? ? } ?
? ? ? ? ??
? ? } ?
??
? ? public String[] getCalendar() { ?
? ? ? ? String[] a = new String[42]; ?
? ? ? ? Calendar rili = Calendar.getInstance(); ?
? ? ? ? rili.set(year, month - 1, 1); ?
? ? ? ? int weekDay = rili.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 = 0; i < weekDay; i++) ?
? ? ? ? ? ? a[i] = ""; ?
? ? ? ? for (int i = weekDay, n = 1; i < weekDay + day; i++) { ?
? ? ? ? ? ? a[i] = String.valueOf(n); ?
? ? ? ? ? ? n++; ?
? ? ? ? } ?
? ? ? ? for (int i = weekDay + day; i < a.length; i++) ?
? ? ? ? ? ? a[i] = ""; ?
? ? ? ? return a; ?
? ? } ?
}?

運(yùn)行結(jié)果:

小結(jié):

學(xué)習(xí)了Calendar類(lèi),其他的,界面的話順著來(lái)就好。

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Springboot采用jasypt加密配置的項(xiàng)目實(shí)踐

    Springboot采用jasypt加密配置的項(xiàng)目實(shí)踐

    本文主要介紹了在Spring Boot項(xiàng)目中使用Jasypt對(duì)配置文件中的敏感信息進(jìn)行加密,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2024-12-12
  • Java中的CAS和ABA問(wèn)題說(shuō)明

    Java中的CAS和ABA問(wèn)題說(shuō)明

    這篇文章主要介紹了Java中的CAS和ABA問(wèn)題說(shuō)明,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2022-05-05
  • 解析Java異步之call future

    解析Java異步之call future

    當(dāng)調(diào)用一個(gè)函數(shù)的時(shí)候,如果這個(gè)函數(shù)的執(zhí)行過(guò)程是很耗時(shí)的,就必須要等待,但是有時(shí)候并不急著要這個(gè)函數(shù)返回的結(jié)果。因此,可以讓被調(diào)者立即返回,讓他在后臺(tái)慢慢處理這個(gè)請(qǐng)求。對(duì)于調(diào)用者來(lái)說(shuō),可以先處理一些其他事情,在真正需要數(shù)據(jù)的時(shí)候再去嘗試獲得需要的數(shù)據(jù)
    2021-06-06
  • SpringBoot中防止接口重復(fù)提交的有效方法

    SpringBoot中防止接口重復(fù)提交的有效方法

    在Web應(yīng)用開(kāi)發(fā)過(guò)程中,接口重復(fù)提交問(wèn)題一直是一個(gè)需要重點(diǎn)關(guān)注和解決的難題,本文將從SpringBoot應(yīng)用的角度出發(fā),探討在單機(jī)環(huán)境和分布式環(huán)境下如何有效防止接口重復(fù)提交,希望通過(guò)本文的介紹,讀者能夠掌握在SpringBoot應(yīng)用中防止接口重復(fù)提交的有效方法
    2024-05-05
  • Spring Cloud Gateway入門(mén)解讀

    Spring Cloud Gateway入門(mén)解讀

    本篇文章主要介紹了Spring Cloud Gateway入門(mén)解讀,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04
  • SpringBoot讀取配置的6種方式

    SpringBoot讀取配置的6種方式

    本文主要介紹了SpringBoot讀取配置的6種方式,主要包括使用默認(rèn)配置、使用application.properties文件、使用application.yml文件、使用@Value注解、使用Environment對(duì)象和使用ConfigurableEnvironment對(duì)象,感興趣的可以了解一下
    2023-08-08
  • SpringBoot整合Security實(shí)現(xiàn)權(quán)限控制框架(案例詳解)

    SpringBoot整合Security實(shí)現(xiàn)權(quán)限控制框架(案例詳解)

    Spring Security是一個(gè)能夠?yàn)榛赟pring的企業(yè)應(yīng)用系統(tǒng)提供聲明式的安全訪問(wèn)控制解決方案的安全框,是一個(gè)重量級(jí)的安全管理框架,本文給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2021-08-08
  • Mybatisplus自動(dòng)填充實(shí)現(xiàn)方式及代碼示例

    Mybatisplus自動(dòng)填充實(shí)現(xiàn)方式及代碼示例

    這篇文章主要介紹了Mybatisplus自動(dòng)填充實(shí)現(xiàn)方式及代碼示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-11-11
  • 純Java實(shí)現(xiàn)數(shù)字證書(shū)生成簽名的簡(jiǎn)單實(shí)例

    純Java實(shí)現(xiàn)數(shù)字證書(shū)生成簽名的簡(jiǎn)單實(shí)例

    下面小編就為大家?guī)?lái)一篇純Java實(shí)現(xiàn)數(shù)字證書(shū)生成簽名的簡(jiǎn)單實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-08-08
  • idea導(dǎo)入若依項(xiàng)目教程

    idea導(dǎo)入若依項(xiàng)目教程

    文章介紹了如何在IntelliJ?IDEA中導(dǎo)入若依管理系統(tǒng)項(xiàng)目,并詳細(xì)步驟包括克隆項(xiàng)目、修改配置文件、創(chuàng)建數(shù)據(jù)庫(kù)、運(yùn)行項(xiàng)目和前端展示
    2025-03-03

最新評(píng)論

宝山区| 龙胜| 清流县| 武平县| 新蔡县| 锦屏县| 西丰县| 蓬莱市| 甘南县| 永和县| 张家川| 玛多县| 黎川县| 临安市| 荃湾区| 曲沃县| 怀安县| 常熟市| 青海省| 吴旗县| 青铜峡市| 乡城县| 内乡县| 榆社县| 万山特区| 常宁市| 桐柏县| 新乐市| 富顺县| 恩施市| 高密市| 浪卡子县| 宿州市| 东乡族自治县| 永兴县| 新干县| 昌黎县| 安阳市| 乌拉特前旗| 灵丘县| 拜城县|