June 2005
Beginner to intermediate
336 pages
6h 29m
English
Now that the user has loaded a new image, you have to make sure that it appears when the window is redrawn. You can do that in the paint method. There's not going to be a lot of fancy animation in this application, so it doesn't use any double buffering. All it does is draw the current image when required in the paint method.
The paint method first makes sure there actually is a BufferedImage object to draw:
public void paint(Graphics g)
{
if(bufferedImage != null){
.
.
.
}
}
If there is an image to draw, you can use the Graphics object passed to the paint method to paint that image, using the Graphics object's drawImage method. Even though that method is usually passed an Image object, you can also pass it a BufferedImage ...
Read now
Unlock full access