I've worked on this code for 2 days and I'm not sure why this applet won't run correctly. It's supposed to accept a parameter called Times which would have time values separated by the | symbol .... 10:15|14:20|8:30 ... and so on. Then it's supposed to create an alarm object for each time and the alarm object is supposed to go off and write to the screen whenever that time has been reached or exceeded. I'm pretty new to writing applets and java in general, so I'm not sure where I'm going wrong. It compiles fine with no errors, but it just won't sound the alarm or write to the screen when the time has been reached. Thanks.
Hi Tyler, Just a few things to help you out. You are using the Calendar functions incorrectly. You are not getting the correct day, month, or year. You should do the following:
The other problem that I can see is that you need to loop in your run method to keep checking the time. Otherwise you will only check once and your done! You also have your comparison backwards. What you want:
I am not sure what you are trying to do by having your AlarmClock extend Applet ... I would just have it pop up a Dialog or something when the alarm is hit and forget trying to have 2 applets. Regards, Manfred.
I agree, I would suggest you have a "pop" window for the the alarm. But anyway, I also agree you are only checking the time once in the AlarmClock in the run method and once you exit the method at the point the thread is dead. craig
Joined: Dec 01, 2000
Thanks for your input and suggestions. I really appreciate it. As for why I'm extending Applet, I was doing that because the applet class provided me with the audioclip class so I can play an alarm sound. I wasn't aware of another way to be able to get the audioclip class without extending applet. I don't understand why you added 1 to the month though that is being returned by the calendar. I didn't see in Sun's documentation that the call to get the month returned the previous month. Is this the case or is there something else going on that I don't see? Thanks.
Joined: Jan 09, 2001
Hi Tyler, The Calendar MONTH value is zero based. Therefore the month of June will be 5. When you use the 5 in your SimpleDateFormat it will be the wrong month. Therefore you will need to add 1 to the value to get the correct date out of your SimpleDateFormat method call. Regards, Manfred.
subject: applet not working..... and I can't figure out why