Are you using the basic java graphics libraries? java.awt, JFrames and the like?
I assume you are (as no other library was mentioned).
This is how I used to do it:
Create a class called DrawGame or something. Make this extend Canvas (I can’t remember which package this belongs to, but you could google it, or, if using eclipse, use ctrl+shift+O to automatically import it).
The DrawGame class will be where you do all of your drawing.
To prevent tearing, you need to double or triple buffer your graphics. To do this, add a member variable to DrawGame of type ‘BufferStrategy’.
In DrawGame’s constructor, call ‘createBufferStrategy(2);’ to create a buffer strategy for the canvas.
next, assign the BufferStrategy member variable to ‘getBufferStrategy()’
When you want to draw anything, simply call ‘getDrawGraphics()’ on the BufferStrategy variable, and store this value in a Graphics object.
After you finish drawing anything, call show() on the strategy and dispose() on the graphics object.
After creating your JFrame, add an instance of DrawGame to it.
To further illustrate this, here is an example class which will draw a square -
http://pastebin.java-gaming.org/e3dee740a0a13
It’s pretty dirty code though.
Have fun:)