以下是引用片段:
class SimpleCanvas extends Canvas{
int w;
int h;
private Image offImage = null;
private boolean buffered = true;
public SimpleCanvas(boolean _buffered){
buffered = _buffered;
w = getWidth();
h = getHeight();
if(buffered)
offImage = Image.createImage(w,h);
}
protected void paint(Graphics g) {
int color = g.getColor();
g.setColor(0xFFFFFF);
g.fillRect(0,0,w,h);
g.setColor(color);
Graphics save = g;
if(offImage != null)
g = offImage.getGraphics();
//draw the offimage
g.setColor(128,128,0);
g.fillRoundRect((w-100)/2,(h-60)/2,100,60,5,3);
//draw the offimage to the canvas
save.drawImage(offImage,0,0,Graphics.TOP|Graphics.LEFT);
}
public Image printMe(){
return offImage;
}
--------------------next---------------------
阅读(427) | 评论(0) | 转发(0) |