Put "extends Canvas" into the class declaration, right after the class name.
In the constructor method, use "setSize(width,height);" to set the size of
the Canvas in pixels, and "setBackground(Color.white)" to set the background
color if desired. Create a Panel
within a Frame; use "myPanel.add(this);" to add the Canvas to the Panel. Then create
a "public void paint(Graphics g)" method, which will be called automatically whenever the
Canvas needs to be drawn.

Graphics methods

g.setColor(Color.red);&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspdraw in a predefined colorg.setColor(new Color(r,g,b));&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspdraw in any color; r,g,b from 0 to 255g.fillRect(left,top,width,height);&nbsp&nbsp&nbspsolid rectangle (drawRect draws outline)g.fillOval(left,top,width,height);&nbsp&nbsp&nbspsolid oval (drawOval draws outline)g.drawLine(x1,y1,x2,y2);&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspdraw a line, one pixel wideg.drawString("Hello",x,y);&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbspdraw text starting at x,y
(All coordinates are integers in pixels, with y measured down from the top of the Canvas.)

Creating a thread

Put "implements Runnable" into the class declaration. In the constructor method, add
the statements "Thread myThread = new Thread(this); myThread.start();". Then create a
run method:

Create a Canvas and a Thread, as described above. Within the loop in the run method,
add the statement "repaint();" to ask Java to call your paint (or update)
method. Set the sleep duration to give about 20 or 30 frames per second.