我有一个非常烦人的问题:
我想画一个图像,我之前加载过(它似乎加载正确)。但是现在发生了一些非常奇怪的事情:有时,图像会出现,有时却不会!但是当我最小化整个框架并再次最大化它时,图像总是在那里!当然,当我绘制图像时,我正在重新绘制整个东西,但正如我所说,没有任何反应,图像不会(总是)显示。
我究竟做错了什么?
好的,问题代码:
//this is the method I load my image with
private BufferedImage loadImage(String name) {
try {
return ImageIO.read(new File(name));
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
//this is the paint method of my JPanel
public void paint(Graphics g){
super.paint(g);
g.drawImage(img, 0, 0, getWidth(), getHeight(), this);
}