启动小程序后,每个组件都绘制正常,除了我的背景图像绘制有大约半秒的延迟。我删除了我的线程,认为这可能是我的问题的原因,但事实并非如此,所以我没有将其包含在这里......我使用双缓冲,因为我的组件由线程重新绘制时会闪烁。我尝试提供尽可能少的代码......
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 毫秒。
关于java - 图像绘制比其他绘制组件晚半秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38107548/