如何使用JCalendar选择我的数组的元素? [英] How to use JCalendar to select an element of my array?

查看:138
本文介绍了如何使用JCalendar选择我的数组的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个三维阵列,其中包含38年中,12个月,每月31项(无论在该月的天数)。像这样:数组[38] [12] [31] 。我也有一个JCalendar,现在是什么都不做,除了寻找pretty和JCalendar有一个按钮的下方。我将如何让这个我可以选择在日历中的日期,那么preSS的按钮,它返回我的阵列,将对应于该日期元素?

I have a 3D array that contains 38 years, 12 months, and 31 entries for each month (regardless of how many days in that month). Like so: array[38][12][31]. I also have a JCalendar that is doing nothing now except looking pretty, and the JCalendar has a button underneath. How would I make it so that I can select a date in the calendar, then press the button and it returns the element of my array that would correspond to that date?

if(buttonPressed){
    year = chosenYear - 1975;
    month = chosenMonth;
    day = chosenDay;

    System.out.print(array[year][month][day]);
}

谢谢你们。

推荐答案

您可以在选定的日期 的PropertyChangeListener ,如图 href=\"http://stackoverflow.com/a/4157956/230513\">。一旦你的日期,你可以从日历的年,月,日:

You can get the selected Date in a PropertyChangeListener, as shown here. Once you have the date, you can get the year, month and day from a Calendar:

Calendar c = Calendar.getInstance();
c.setTime(date);
int y = c.get(Calendar.YEAR);
int m = c.get(Calendar.MONTH);
int d = c.get(Calendar.DAY_OF_MONTH);

的Calendar.MONTH 已经是零基础,但 Calendar.DAY_OF_MONTH 不是;你会需要一年来适应你的基线。

Calendar.MONTH is already zero-based, but Calendar.DAY_OF_MONTH is not; and you'll need to adjust the year to your baseline.

这篇关于如何使用JCalendar选择我的数组的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆