See the following tutorial:
Lesson: Working with Images (The Java™ Tutorials > 2D Graphics)
You'll need to create an Image (see Creating and Drawing to an Image), get its graphics, and draw to it,...