我有 3 个 JSpinner,一个持续几个小时,一个持续几分钟,一个持续几秒钟。分钟和秒的最大值为 60,最小值为 -1,小时的最小值为 -1,最大值为 24。如果第二个达到 60,它会翻转回 0 并将分钟一一增加。小时和分钟的向下函数和向上和向下函数也有类似的行为。这种技术在 24 小时时间中运行时非常有效。
然而,我在 12 小时内就遇到了问题。我的左侧有一个 JCheckBox
(amPmCheckBox
),用于激活或停用 12 小时制时间。现在,与 12 小时时间之间的转换也可以完美地工作,因此单击此 JCheckBox
不是问题。您会看到,左侧有一个 JToggleButton
(amPmToggleButton
)。如果向上(取消选择)则显示 AM,如果向下(选择)则显示 PM。
现在,问题不在于转换(记住,我说过有效),而在于滚动。当我向上滚动微调器查看时间时,它应该从晚上 11 点到凌晨 12 点。然而,我有它,以便每次小时微调器达到其限制之一并翻转回来时,amPmToggleButton
都会切换其状态(这很容易检测到。我只需检查getAlarmHrs() > ; MAX_ALARM_AMPM_HRS
else if getAlarmHrs() 。) 现在,这就是我的问题。每个 AM/PM 周期有 12 个小时,这是应该有的。不过,营业时间为凌晨 1 点至 12 点以及下午 1 点至 12 点。任何了解 AM/PM 的人都知道这是错误的。
如何对其进行编程以了解何时在上午和下午之间切换?
请记住,此闹钟在 24 小时内运行绝对完美。
I have 3 JSpinner
s, one for hours, one for minutes, one for seconds. The minutes and seconds have a max of 60 and a min of -1 and the hours one has a min of -1 and a max of 24. If the second one hits 60, it flips back to 0 and increases the minutes one by one. There is similar behavior for the down function and the up and down function of the hours and minutes one. This technique works flawlessly when navigating through 24-hour time.
HOWEVER, I hit problems in 12-hour time. I have a JCheckBox
(amPmCheckBox
) to the left that activates or deactivates 12-hour time. Now, converting to/from 12-hour time works flawlessly as well, so the clicking of this JCheckBox
is not the problem. There a JToggleButton
(amPmToggleButton
) to the left, you see. This displays AM if it is up (deselected) and PM if it is down (selected).
Now, the problem lies not in converting (remember, I said that worked), but in scrolling. When I scroll the spinner up through the hours, it SHOULD go from, say, 11 PM to 12 AM. HOWEVER, I have it so that the amPmToggleButton
switches its state every time the hour spinner hits one of its limits and flips back (which is easy to detect. I just check if getAlarmHrs() > MAX_ALARM_AMPM_HRS
else if getAlarmHrs() < MIN_HRS
.) Now, therein lies my problem. There ARE 12 hours per AM/PM cycle, as there should be. HOWEVER, they go from 1 AM - 12 AM and 1 PM - 12 PM. Anyone who knows AM/PM knows this is wrong.
How do I program this to know when to switch between AM and PM?
Remember that this alarm clock works absolutely perfectly in 24-hr time.
发布评论
评论(1)
经过这么长时间,我采用了更强大的格式,并通过使用完全不同的设置解决了这个问题。基本的解决方案是去中心化一切;它越模块化,就越容易修复。如果有人访问此问题并想要更详细的答案,只需发表评论,我很乐意提供。
After all this time, I've gone with a much more robust format and have fixed this problem by using a totally different setup. The basic solution was to decentralize everything; the more modular it is, the easier it is to fix. If anyone visits this question and wants a more detailed answer, simply comment so and I'll be happy to provide it.