width = getSize().width; height = getSize().height; pixData = new int [width * height]; int i=0; for (int y = 0; y < height; y++) { int red = (y * 255) / (height - 1); for (int x = 0; x < width; x++) { int green = (x * 255) / (width - 1); int blue = 128; int alpha = 255; pixData[i++] = (alpha << 24) | (red << 16) | (green << 8 ) | blue; } }
if ( img == null ) img = createImage( new MemoryImageSource(width, height, pixData, 0, width)); g.drawImage( img, 0, 0, this );