This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

applet not working..... and I can't figure out why

 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

[ June 04, 2002: Message edited by: tyler jones ]
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Craig Jackson
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
tyler jones
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic