quadrar
quadrar

Reputation: 5

image is drawn half second later then other paint compontents

After I start my applet every component is drawn alright, besides my background image that is drawn with about a half second delay. I deleted my thread thinking it's maybe the cause of my problem, but it's not, so i didn't include it here.... I use Double Buffering, because I would have flickering of my components that are repainted by thread. I tried to provide as little code as possible....

public class balg extends Applet implements Runnable {


   private Image i;
   private Graphics doubleG;
   URL url;
   Image city;  //background image


   public void init(){
      setSize(800, 600);

      try{
          url = getDocumentBase();
      }catch(Exception e){

      }
      city = getImage(url , "multiplen/images/SPACE.png");
   }


   public void start(){

        Thread thread = new Thread(this);
        thread.start();

   }

   public void run(){

     // here goes the repiant();

   }

   public void stop(){


   }

   public void destroy(){


   }

   @Override
   public void update(Graphics g) {
      if(i == null){
           i = createImage(this.getSize().width, this.getSize().height);
           doubleG = i.getGraphics();
      }

      doubleG.setColor(getBackground());
      doubleG.fillRect(0, 0, this.getSize().width, this.getSize().height);

      doubleG.setColor(getForeground());
      paint(doubleG);

      g.drawImage(i, 0,0, this);
   }

   public void paint(Graphics g){

      g.drawImage(city,(int) 800 , 0 , this); // it's drawn here

      String s = "15";  
      g.setColor(Color.BLACK);
      g.drawString(s, getWidth() - 150, 50);    
   }

 }

Upvotes: 0

Views: 41

Answers (1)

gpasch
gpasch

Reputation: 2682

It takes that much time to read the image, about 100-200 ms.

Upvotes: 1

Related Questions