Take a look at the tutorial: Trail: 2D Graphics (The Java™ Tutorials)