FileDocCategorySizeDatePackage
Gradient.javaAPI DocExample6818Wed Aug 08 15:13:48 BST 2001demos.Paint

Gradient

public class Gradient extends ControlsSurface

Fields Summary
protected Color
innerC
protected Color
outerC
private DemoControls
controls
Constructors Summary
public Gradient()

        setBackground(Color.white);
        innerC = Color.green;
        outerC = Color.blue;
        setControls(new Component[] { new DemoControls(this) });
    
Methods Summary
public static voidmain(java.lang.String[] s)

        createDemoFrame(new Gradient());
    
public voidrender(int w, int h, java.awt.Graphics2D g2)


        int w2 = w/2;
        int h2 = h/2;
        g2.setPaint(new GradientPaint(0,0,outerC,w*.35f,h*.35f,innerC));
        g2.fillRect(0, 0, w2, h2);
        g2.setPaint(new GradientPaint(w,0,outerC,w*.65f,h*.35f,innerC));
        g2.fillRect(w2, 0, w2, h2);
        g2.setPaint(new GradientPaint(0,h,outerC,w*.35f,h*.65f,innerC));
        g2.fillRect(0, h2, w2, h2);
        g2.setPaint(new GradientPaint(w,h,outerC,w*.65f,h*.65f,innerC));
        g2.fillRect(w2, h2, w2, h2);

        g2.setColor(Color.black);
        TextLayout tl = new TextLayout(
                "GradientPaint", g2.getFont(), g2.getFontRenderContext());
        tl.draw(g2, (int) (w/2-tl.getBounds().getWidth()/2),
                (int) (h/2+tl.getBounds().getHeight()/2));