Setting Text Color

To set the text and background color of the text, call the Graphics object's setBackColor and setTextColor before calling drawString:

// Set the text to white, the background to black.

g.setTextColor(new Color(0, 0, 0));

g.setBackColor(new Color(255, 255, 255));

// Draw the text...

The setBackColor method affects only the background color of text. To set the background or fill color for other objects, such as polygons and lines, use the setBrush and setPen methods, respectively.