代码如下用的是JFrame
(Image background)
public void paint(Graphics g){
if(background == null || background.getWidth(this) < 0 ||
background.getHeight(this) < 0){
background = getToolkit().getImage("images\\background.jpg");
g.drawImage(background, 0, 20, this);
}
}
测试中 在if语句中加System.out.print可以输出
背景加颜色也行,画线条之类的其他图形也行,就是图片有问题
求教~在线等~
(Image background)
public void paint(Graphics g){
if(background == null || background.getWidth(this) < 0 ||
background.getHeight(this) < 0){
background = getToolkit().getImage("images\\background.jpg");
g.drawImage(background, 0, 20, this);
}
}
测试中 在if语句中加System.out.print可以输出
背景加颜色也行,画线条之类的其他图形也行,就是图片有问题
求教~在线等~
background = getToolkit().getImage("images\\background.jpg");
to
......
MediaTracker mt = new MediaTracker(this);
background= Toolkit.getDefaultToolkit().getImage("images\\background.jpg");
mt.addImage(background, 0);
try {
mt.waitForAll();
} catch (InterruptedException e) {
e.printStackTrace();
}
.........
Hope it helps.//Ali