applet is running 3 times instead of 1 time

by wolf » Mon, 26 Jan 1998 03:00:00 GMT



Hi everybody!
this applet below runns three time instead of one.
even inserting the mediatracker class did not fix the problem.
who can help?
many thanks for help
peter
import java.awt.*;
import java.applet.*;
public class picturemove extends Applet implements Runnable
{
 Image bild;
 String dateiname;
 public void init()
 {
  dateiname="sarajevo1.gif";
  MediaTracker mt = new MediaTracker(this);
  bild=getImage(getCodeBase(),dateiname);
  mt.addImage(bild,0);
  try
  {
   mt.waitForAll();
  }
  catch (Exception e) {};
 }
 public void run()
 {
  repaint();
 }
 public void paint(Graphics g)
 {
  int x;
  int h=(size().height/2)-35;
     int b=(size().width/2)-35;
  for (x=size().height; x>=b ;x--)
   g.drawImage(bild,b,x,this);
  try
   {
    Thread.sleep(50);
   }
   catch(Exception e){}
   if(x!=h)
   g.clearRect(0,0,size().width,size().height);
 }
}




applet is running 3 times instead of 1 time

by Jonathan Revusk » Wed, 28 Jan 1998 03:00:00 GMT




> Hi everybody!
> this applet below runns three time instead of one.

For one thing, I don't know what you're doing with run()
and extending runnable. Your code doesn't seem to initiate
any threads.
But anyway, if you want a method to run exactly once, why not just
do this?
static boolean run_already = false;
public void init() {
   if (run_already) return;
   run_already = true;
   .....
}

Greetings from Spain
Jonathan Revusky
jrevu...@jet.es