import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class JGradientJavaExample extends JFrame
{
public void paint(Graphics gr)
{
super.paint(gr);
int x = 20, y = 40, x2 = 160, y2 = 80;
Graphics2D GR2D = (Graphics2D)gr;
GR2D.setPaint(new GradientPaint(x, y, Color.LIGHT_GRAY,
x2, y2, Color.DARK_GRAY, false));
GR2D.fill(new Rectangle2D.Double(x, y, x2, y2));
x = 200;
GR2D.setPaint(new GradientPaint(x, y, Color.LIGHT_GRAY,
x2, y2, Color.DARK_GRAY, true));
GR2D.fill(new Rectangle2D.Double(x, y, x2, y2));
}
public static void main(String[] gs)
{
JGradientJavaExample frm = new JGradientJavaExample();
frm.setSize(440,180);
frm.setVisible(true);
}
}