{
g.drawImage(screenImage, // draw it
w/2 - screenImage.getWidth(this) / 2, // at the center
h/2 - screenImage.getHeight(this) / 2, // of screen
this);
// to draw image at the center of screen
// we calculate X position as a half of screen width minus half of image width
// Y position as a half of screen height minus half of image height
}
}
}
注意:
如果图像未成功装载,本程序就没有输出。