用Component.prepareImage,然后再 g.drawImagepublic boolean prepareImage( Image image, ImageObserver observer ) Parameters image the Image for which to prepare a screen representation. observer the ImageObserver object to be notified as the image is being prepared. Returns true if the image has already been fully prepared; false otherwise. Description Prepares an image for rendering on this component. The image data is downloaded asynchronously in another thread and the appropriate screen representation of the image is generated.
Component类实现了ImageObserver这个接口,
比如在Applet里画图,直接把Applet对象作为ImageObserver参数即可
JButton jb = new JButton("asdf",img);
我是要对JButton的paintComponent方法进行重写,所以要使用到drawImage
并不是你所想象的那样的意思。谢谢
{
g.drawImage(img,0, 0, null) ;
}
现在,我不值到该怎样用ImageObserver
Parameters
image
the Image for which to prepare a screen representation.
observer
the ImageObserver object to be notified as the image is being prepared.
Returns
true if the image has already been fully prepared; false otherwise.
Description
Prepares an image for rendering on this component. The image data is downloaded asynchronously in another thread and the appropriate screen representation of the image is generated.