• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic