图像绘制比其他绘制组件晚半秒



在我启动我的applet后,每个组件都画好了,除了我的背景图像,它是用大约半秒的延迟绘制的。我删除了我的线程认为这可能是我的问题的原因,但它不是,所以我没有包括它在这里....我使用双缓冲,因为我将有闪烁的组件被线程重新绘制。我试图提供尽可能少的代码....

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);    
   }
 }

读取图像需要这么多时间,大约100-200毫秒。

最新更新