MathBits.com
Return to Unit Menu | Java Main Page | MathBits.com | Terms of Use  
 

Filling Graphics with Color

These commands will draw the figure and fill the space with color. 

EDGE:  If you want a distinct "edge" around the figure, also draw the figure in a contrasting color after the fill command. 

  g.setColor(Color.orange);
g.fillRect(35,45,75,95);

    

 

g.setColor(Color.orange);
g.fillRect(35,45,75,95);
g.setColor(Color.black);
g.drawRect(35, 45, 75, 95);

       

 

Fill an Arc g.fillArc(35, 45, 75, 95, 0, 90);

Draws and fills an arc with a previously set color.

Fill an Oval g.fillOval(35, 45, 75, 95);

Draws and fills an oval with a previously set color.

Fill a Rectangle g.fillRect(35, 45, 75, 95);
Draws and fills a rectangle with a previously set color.

Fill a Round Rectangle

 

g.fillRoundRect(2,2,25,35,20,20);

Draws and fills with a previously set color.

Fill a Polygon

 

int [ ] x = {20, 20, 30, 50, 30, 20};
int [ ] y = {10, 25, 35, 40, 35, 30};
g.fillPolygon(x, y, 6);

Draws and fills a polygon with a previously set color.


 


Return to Unit Menu | Java Main Page | MathBits.com | Terms of Use