public static void clearRect(Graphics2D g,Rectangle rect,Color background){
  if (background != null) {
    g.setColor(background);
    g.fillRect(rect.x,rect.y,rect.width,rect.height);
  }
 else {
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.CLEAR,0.0f));
    g.fillRect(rect.x,rect.y,rect.width,rect.height);
    g.setComposite(AlphaComposite.SrcOver);
  }
}

public static void clearRect ( Graphics2D g , Rectangle rect , Color background ) { if ( background != null ) { g . setColor ( background ) ; g . fillRect ( rect . x , rect . y , rect . width , rect . height ) ; } else { g . setComposite ( AlphaComposite . getInstance ( AlphaComposite . CLEAR , 0.0f ) ) ; g . fillRect ( rect . x , rect . y , rect . width , rect . height ) ; g . setComposite ( AlphaComposite . SrcOver ) ; } }
clears the given area of the specified graphics object with the given color or makes the region transparent .
