tutorial java create Panel Gradient


lets rock !

a. The first step, open the NetBeans IDE

b. create a new project and name it PanelGradient

c. create a new Java Class and name ClassGradient

d. create new JFrame Form and give it name MainForm

e. insert the following syntax in the source code ClassGradient.java

package panelgradient;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.geom.GeneralPath;
import java.awt.image.BufferedImage;
import javax.swing.JPanel;

 * @author CodeMaster
public class ClassGradient extends JPanel {
    private BufferedImage gambarGradient;
    private Color warna1 = Color.BLACK;
    private Color warna2 = Color.BLUE;

    public ClassGradient() {

    protected void paintComponent(Graphics g) {
        super.paintComponent(g); //To change body of generated methods, choose Tools | Templates.
            Graphics2D g2d = (Graphics2D) g.create();
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g2d.drawImage(gambarGradient, 0, 0, getWidth(), getHeight(), null);

            int lebar = getWidth();
            int tinggi = getHeight() * 5 / 100;

            Color light = new Color(1F, 1F, 1F, 0.5F);
            Color dark = new Color(1F, 1F, 1F, 0.0F);

            GradientPaint paint = new GradientPaint(0, 0, light, 0, tinggi, dark);
            GeneralPath path = new GeneralPath();
            path.moveTo(0, 0);
            path.lineTo(0, tinggi);
            path.curveTo(0, tinggi, lebar / 2, tinggi / 2, lebar, tinggi);
            path.lineTo(lebar, 0);


            paint = new GradientPaint(0, getHeight(), light, 0, getHeight() - tinggi, dark);
            path = new GeneralPath();
            path.moveTo(0, getHeight());
            path.lineTo(0, getHeight() - tinggi);
            path.curveTo(0, getHeight() - tinggi, lebar / 2, getHeight() 
                        - tinggi / 2, lebar, getHeight() - tinggi);
            path.lineTo(lebar, getHeight());

     * membuat background gradient
    private void setUpGradient() {
        gambarGradient = new BufferedImage(1, getHeight(), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2 = (Graphics2D) gambarGradient.getGraphics();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        GradientPaint paint = new GradientPaint(0, 0, warna1, 0,getHeight(), warna2);

        g2.fillRect(0, 0, 1, getHeight());
f. Clean and Build or press Shift + F11

g.drag and drop design tab page mainForm.java

h. Set JFrame layout mainForm.java, right click select setLayout and select BorderLayout

i. Running the program or press Shift + F6

its easy guys !
hope it is useful! please write comment and share this !

tutorial java create Panel Gradient
Item Reviewed: tutorial java create Panel Gradient 9 out of 10 based on 10 ratings. 9 user reviews.

0 Response to "tutorial java create Panel Gradient"

Post a Comment

Ads Inside Post