Here you can find the source of DrawGradient(Graphics g, int x, int y, int width, int height, Color color1, Color color2)
Parameter | Description |
---|---|
g | the graphics object to use to draw with |
x | the left position |
y | the top position |
width | with width of the gradient |
height | the height of the gradient |
color1 | the first color of the gradient |
color2 | the second color of the gradient |
public static void DrawGradient(Graphics g, int x, int y, int width, int height, Color color1, Color color2)
//package com.java2s; //License from project: Open Source License import java.awt.*; import java.awt.geom.Rectangle2D; public class Main { /**// w ww . jav a 2 s . co m * Draws a gradient * @param g the graphics object to use to draw with * @param x the left position * @param y the top position * @param width with width of the gradient * @param height the height of the gradient * @param color1 the first color of the gradient * @param color2 the second color of the gradient */ public static void DrawGradient(Graphics g, int x, int y, int width, int height, Color color1, Color color2) { Graphics2D graphics2D = (Graphics2D) g; { GradientPaint gradient = new GradientPaint(width / 2, y, color1, width / 2, height / 2, color2); Rectangle2D rect = new Rectangle2D.Double(x, y, width, height / 2); graphics2D.setPaint(gradient); graphics2D.fill(rect); } { GradientPaint gradient = new GradientPaint(width / 2, height / 2, color2, width / 2, height, color1); Rectangle2D rect = new Rectangle2D.Double(x, y + height / 2, width, height); graphics2D.setPaint(gradient); graphics2D.fill(rect); } } }