posted 24 years ago
Donna,
I am a little confused, because your code works as expected on my machine. Like we discussed, if the user put in a "wrong" date, it is still accepted. I don't think there is any way around that using the Calendar class. You would have to write your own data validation routine, like below:
Note that adding a key listener prevents the user from entering anything other than digits or slashes, so you really only need to check the validity of the month and date.
However, I don't understand why you say that
"I'm concerned about the user putting in a wrong date liked 1/32/00 and NOT meaning 2/1/00. If it works this way, how do I know if it's calculating a leap year?"
It seems to me that whether or not it is a leap year doesn't make any difference. For example, say the user enters "02/30/00". This is obviously wrong whether it is a leap year or not. But your code handles it as expected. 2000 IS a leap year, so February has 29 days. Therefore, "02/30/00" is interpreted as March 1, 2000, which is the 61st day of the year. If you take a year which is NOT a leap year, like 1999: "02/30/99" is interpreted as March 2, 1999, which is STILL the 61st day of the year.
Could you please explain your concern a little further?
Thanks.
Stephanie