public void fillRectRadialGradient(Object graphics,int startColor,int endColor,int x,int y,int width,int height,float relativeX,float relativeY,float relativeSize){
  int centerX=(int)(width * (1 - relativeX));
  int centerY=(int)(height * (1 - relativeY));
  int size=(int)(Math.min(width,height) * relativeSize);
  int x2=(int)(width / 2 - (size * relativeX));
  int y2=(int)(height / 2 - (size * relativeY));
  boolean aa=isAntiAliased(graphics);
  setAntiAliased(graphics,false);
  if (cacheRadialGradients()) {
    Object r=findCachedGradient(radialGradientCache,startColor,endColor,x,y,width,height,true,centerX,centerY,size);
    if (r != null) {
      drawImage(graphics,r,x,y);
    }
 else {
      r=createMutableImage(width,height,0xffffffff);
      Object imageGraphics=getNativeGraphics(r);
      setColor(imageGraphics,endColor);
      fillRect(imageGraphics,0,0,width,height);
      fillRadialGradientImpl(imageGraphics,startColor,endColor,x2,y2,size,size,0,360);
      drawImage(graphics,r,x,y);
      if (radialGradientCache == null) {
        radialGradientCache=new Hashtable();
      }
      storeCachedGradient(r,radialGradientCache,startColor,endColor,x,y,true,centerX,centerY,size);
    }
  }
 else {
    setColor(graphics,endColor);
    fillRect(graphics,x,y,width,height);
    fillRadialGradientImpl(graphics,startColor,endColor,x + x2,y + y2,size,size,0,360);
  }
  if (aa) {
    setAntiAliased(graphics,true);
  }
}

public void fillRectRadialGradient ( Object graphics , int startColor , int endColor , int x , int y , int width , int height , float relativeX , float relativeY , float relativeSize ) { int centerX = ( int ) ( width * ( 1 - relativeX ) ) ; int centerY = ( int ) ( height * ( 1 - relativeY ) ) ; int size = ( int ) ( Math . min ( width , height ) * relativeSize ) ; int x2 = ( int ) ( width / 2 - ( size * relativeX ) ) ; int y2 = ( int ) ( height / 2 - ( size * relativeY ) ) ; boolean aa = isAntiAliased ( graphics ) ; setAntiAliased ( graphics , false ) ; if ( cacheRadialGradients ( ) ) { Object r = findCachedGradient ( radialGradientCache , startColor , endColor , x , y , width , height , true , centerX , centerY , size ) ; if ( r != null ) { drawImage ( graphics , r , x , y ) ; } else { r = createMutableImage ( width , height , 0xffffffff ) ; Object imageGraphics = getNativeGraphics ( r ) ; setColor ( imageGraphics , endColor ) ; fillRect ( imageGraphics , 0 , 0 , width , height ) ; fillRadialGradientImpl ( imageGraphics , startColor , endColor , x2 , y2 , size , size , 0 , 360 ) ; drawImage ( graphics , r , x , y ) ; if ( radialGradientCache == null ) { radialGradientCache = new Hashtable ( ) ; } storeCachedGradient ( r , radialGradientCache , startColor , endColor , x , y , true , centerX , centerY , size ) ; } } else { setColor ( graphics , endColor ) ; fillRect ( graphics , x , y , width , height ) ; fillRadialGradientImpl ( graphics , startColor , endColor , x + x2 , y + y2 , size , size , 0 , 360 ) ; } if ( aa ) { setAntiAliased ( graphics , true ) ; } }
draws a radial gradient in the given coordinates with the given colors , doesn ' t take alpha into consideration when drawing the gradient . notice that a radial gradient will result in a circular shape , to create a square use fillrect or draw a larger shape and clip to the appropriate size .
