by Dinesh Thakur Category: Swing

 

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);
                         }
}

Gradient in Java Swing Example



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Related Articles