Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Java is looping my applet?

Started by capn_midnight Apr 24, 2001 at 11:20 AM 1 replies 400+ views
Original Post
capn_midnight
capn_midnight
I''ve just started with Java, though I''ve been coding C/C++ for about 2 years and java-script for about 5, so I am very familiar with the syntax. I wrote this simple applet the other day, and it did something completely unexpected (or atleast I didn''t expect it)
  
public JavaAp3 extends Applet
{
   public paint(Graphics g)
   {
      int x,n,m;
      Image img;
      img=getImage(getCodeBase(),"knight.gif");
      x=(int)(Math.random*25);
      while(x>=0){
         n=(int)(Math.random*200);
         m=(int)(Math.random*200);
         g.drawImage(img,n,m,this);
         x--;
      }
   }
}
  
Now, I thought this would run once and I would have a random number of knights at random locations on the screen. But instead, it continues to rerun the applet over and over again, so that I have a random number of knights constantly blinking on the screen over and over again. Can I make it stop? How can I take advantage of this? Is there a faster way of putting stuff on screen (this is almost as slow as java-script)? Are you even trying to be intelligent? ''cuz if you are, it ain''t workin'' Down with Tiberia!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.