Question

I have 3 JSpinners, 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top