Setting the Brush on the Graphics Object

Like the Pen and Font objects, the Brush object contains no coloring or drawing capability. It expresses a subset of the capabilities of the GDI. Before a brush can be used to fill surfaces, it must be associated with a Graphics object using the setBrush method:

protected void onPaint(PaintEvent e)
{

 // Create a forward diagonal brush, and associate it with the
    // object.
    Brush br = new Brush(Color.BLACK, BrushStyle.FORWARDDIAGONAL);
    e.graphics.setBrush(br);

}

After you associate a Brush object with the Graphics object, all polygons that you draw using that Graphics object instance are filled with the associated brush. You can call setBrush as often as you want to associate a new brush with the Graphics object.