• Post Reply Bookmark Topic Watch Topic
  • New Topic

Paint() of one applet slows down second applet ?  RSS feed

 
Jeroen Verbeeck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a html page, which contains 2 applets :
- the first one contains moving images (spheres) that bouce around randomly
To get fluent motion, I calculate their position and repaint often.
- the second applet is empty initially, but get notified by the first applet

Here my problem occurs: when the 2nd starts to paint, it slows down the movement of the 1st applet. When it is done, the speed of the 1st applet goes back to normal ?!

What could be causing this ? Any ideas ?

I suppose I could be caused by a thread-problem (since both applets use a thead to wait and repaint) but I can't seem to find it.

Any help is greatly appreciated !!
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If they are both running in the same virtual machine (which they probably are, in the same web page) they are using the same thread to refresh displays. You can free up that thread by creating another thread to do the dirty work of calculating motion, drawing the next image and so on. Have a look at the Java Tutorial chapter on How To Use Threads to get started.
 
Jeroen Verbeeck
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Last night I changed my code and moved the time-consuming operations out of the paint method. This way it completes more quickly and both applets can paint their objects fluently.

Now it works fine ! Thank you for pointing me in the right direction, as I was unaware of the event-dispatching thread.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!