Here you can find the source of drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode)
static public void drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode)
//package com.java2s; import java.awt.Color; import java.awt.GradientPaint; import java.awt.Graphics2D; import java.util.Vector; public class Main { static public void drawRainbow(Graphics2D g2, int x, int y, int Width, int Height, int Mode) { Vector Colors = new Vector(); GradientPaint gp;// w w w. j a va 2 s. co m switch (Mode) { case 1: Colors.add(new Color(255, 000, 000)); Colors.add(new Color(255, 255, 000)); Colors.add(new Color(000, 255, 000)); Colors.add(new Color(000, 255, 255)); Colors.add(new Color(000, 000, 255)); Colors.add(new Color(255, 000, 255)); break; case 2: Colors.add(new Color(255, 000, 000)); Colors.add(new Color(255, 255, 000)); Colors.add(new Color(000, 000, 128)); break; case 3: Colors.add(new Color(255, 000, 255)); Colors.add(new Color(000, 000, 255)); Colors.add(new Color(000, 255, 255)); Colors.add(new Color(000, 255, 000)); Colors.add(new Color(255, 255, 000)); Colors.add(new Color(255, 000, 000)); break; } double Step = Width / (double) (Colors.size() - 1); for (int i = 0; i < (Colors.size() - 1); i++) { gp = new GradientPaint(x + (int) Math.round(i * Step), 0, (Color) Colors.get(i), x + (int) Math.round((i + 1) * Step), 0, (Color) Colors.get(i + 1)); g2.setPaint(gp); g2.drawRect(x + (int) Math.round(i * Step), y, (int) Step, Height); g2.fillRect(x + (int) Math.round(i * Step), y, (int) Step, Height); } } }