Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Older applets not working correctly?  RSS feed

 
Ian Witham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

I've been working my way through 'Sams Teach Yourself Java 2. in 24 Hours' I realise that this book dates back to the 1.2 JDK.

A couple of the applet lessons on using threads with Audioclips and animations don't seem to work correctly on two newer computers using win XP and java 1.5, but they work fine on a win 98 computer with java 1.41.

The applets are: MathMan.html
(the applet intermittently leaves a silent pause instead of playing a word)

Animate.html
(Applet should cycle through 4 images in order but seems to randomly skip through the images)

Is there a modification I can make to the code that will fix this?

Any advice would be appreciated.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ian Witham:
I've been working my way through 'Sams Teach Yourself Java 2. in 24 Hours' I realise that this book dates back to the 1.2 JDK.

A couple of the applet lessons on using threads with Audioclips and animations don't seem to work correctly on two newer computers using win XP and java 1.5, but they work fine on a win 98 computer with java 1.41.

Animate.html
(Applet should cycle through 4 images in order but seems to randomly skip through the images)


Using Java 1.4 and Win2K, I notice that this applet occasionally skips an image. Perhaps it works on the Win98 box because it is slower. Interesting problem.
 
Ian Witham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've tried increasing the length of the sleep to several seconds in both cases. That doesn't seem to help at all.

The code seems so simple for these applets that it's hard for me to see what the problem could be.

I'd like to identify the problem so that I don't include it in my own code.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After looking into it a little more, I see that the problem in the Animate code is that the thread is modifying a "global variable" which is being used by another method. This is causing an Exception at random times causing the applet to skip one of the four images at those times.

If you take

out of the run() method and put it into the paint() method, leaving the call to repaint() and the call to sleep() in the run() method, it works just fine.
[ May 01, 2005: Message edited by: Marilyn de Queiroz ]
 
Ian Witham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank-you, I think I understand what's going on there.

I'm looking for a way to apply the same kind of solution to the MathMan applet but I haven't had any luck so far.

I'll keep trying but in the mean-time any hints are welcome.
 
Marilyn de Queiroz
Sheriff
Posts: 9080
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did not experience any problems with the MathMan applet. Nor did I see anything similar in the code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!