That is NOT the way to do painting. I suggest you read this: Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)

But really, what you're looking for is...