public void paint(Graphics g,int x,int y,int w,int h){
  Rectangle clipRect=g.getClipBounds();
  int minX=Math.max(x,clipRect.x);
  int minY=Math.max(y,clipRect.y);
  int maxX=Math.min(clipRect.x + clipRect.width,x + w);
  int maxY=Math.min(clipRect.y + clipRect.height,y + h);
  if (maxX <= minX || maxY <= minY) {
    return;
  }
  int xOffset=(minX - x) % 2;
  for (int xCounter=minX; xCounter < maxX; xCounter+=BUFFER_SIZE) {
    int yOffset=(minY - y) % 2;
    int width=Math.min(BUFFER_SIZE - xOffset,maxX - xCounter);
    for (int yCounter=minY; yCounter < maxY; yCounter+=BUFFER_SIZE) {
      int height=Math.min(BUFFER_SIZE - yOffset,maxY - yCounter);
      g.drawImage(image,xCounter,yCounter,xCounter + width,yCounter + height,xOffset,yOffset,xOffset + width,yOffset + height,null);
      if (yOffset != 0) {
        yCounter-=yOffset;
        yOffset=0;
      }
    }
    if (xOffset != 0) {
      xCounter-=xOffset;
      xOffset=0;
    }
  }
}

public void paint ( Graphics g , int x , int y , int w , int h ) { Rectangle clipRect = g . getClipBounds ( ) ; int minX = Math . max ( x , clipRect . x ) ; int minY = Math . max ( y , clipRect . y ) ; int maxX = Math . min ( clipRect . x + clipRect . width , x + w ) ; int maxY = Math . min ( clipRect . y + clipRect . height , y + h ) ; if ( maxX <= minX || maxY <= minY ) { return ; } int xOffset = ( minX - x ) % 2 ; for ( int xCounter = minX ; xCounter < maxX ; xCounter += BUFFER_SIZE ) { int yOffset = ( minY - y ) % 2 ; int width = Math . min ( BUFFER_SIZE - xOffset , maxX - xCounter ) ; for ( int yCounter = minY ; yCounter < maxY ; yCounter += BUFFER_SIZE ) { int height = Math . min ( BUFFER_SIZE - yOffset , maxY - yCounter ) ; g . drawImage ( image , xCounter , yCounter , xCounter + width , yCounter + height , xOffset , yOffset , xOffset + width , yOffset + height , null ) ; if ( yOffset != 0 ) { yCounter -= yOffset ; yOffset = 0 ; } } if ( xOffset != 0 ) { xCounter -= xOffset ; xOffset = 0 ; } } }
paints the grid into the specified graphics at the specified location .
