Look at the tutorial on painting:
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)