gradient Fill Rect - Java 2D Graphics

Java examples for 2D Graphics:Rectangle

Description

gradient Fill Rect

Demo Code


//package com.java2s;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics2D;

public class Main {
    /**/*from w  w  w  .  j a  v  a2s .  com*/
     * @param ct
     * @param baseColor
     * @param hiliteColor
     * @param px
     * @param py
     * @param w
     * @param h
     */
    public static void gradientFillRect1(Graphics2D ct, Color baseColor,
            Color hiliteColor, int px, int py, int w, int h) {
        int h2 = h / 4;
        int py2 = py + h2;
        ct.setPaint(new GradientPaint(px, py, baseColor, px, py2 - 1,
                hiliteColor));
        ct.fillRect(px, py, w, h2);
        ct.setPaint(new GradientPaint(px, py2, hiliteColor, px, py + h - 1,
                baseColor));
        ct.fillRect(px, py2, w, h - h2);
    }
}

Related Tutorials