Example usage for java.awt Color Color

List of usage examples for java.awt Color Color

Introduction

In this page you can find the example usage for java.awt Color Color.

Prototype

public Color(ColorSpace cspace, float[] components, float alpha) 

Source Link

Document

Creates a color in the specified ColorSpace with the color components specified in the float array and the specified alpha.

Usage

From source file:ColorUtil.java

/**
 * Decode an HTML color string like '#F567BA;' into a {@link Color}
 * @param colorString The string to decode
 * @return The decoded color/*from ww  w .  jav a  2 s .  c om*/
 * @throws IllegalArgumentException if the color sequence is not valid
 */
public static Color decodeHtmlColorString(String colorString) {
    Color color;

    if (colorString.startsWith("#")) {
        colorString = colorString.substring(1);
    }
    if (colorString.endsWith(";")) {
        colorString = colorString.substring(0, colorString.length() - 1);
    }

    int red, green, blue;
    switch (colorString.length()) {
    case 6:
        red = Integer.parseInt(colorString.substring(0, 2), 16);
        green = Integer.parseInt(colorString.substring(2, 4), 16);
        blue = Integer.parseInt(colorString.substring(4, 6), 16);
        color = new Color(red, green, blue);
        break;
    case 3:
        red = Integer.parseInt(colorString.substring(0, 1), 16);
        green = Integer.parseInt(colorString.substring(1, 2), 16);
        blue = Integer.parseInt(colorString.substring(2, 3), 16);
        color = new Color(red, green, blue);
        break;
    case 1:
        red = green = blue = Integer.parseInt(colorString.substring(0, 1), 16);
        color = new Color(red, green, blue);
        break;
    default:
        throw new IllegalArgumentException("Invalid color: " + colorString);
    }
    return color;
}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(Color.red);/* w w w  .j  ava  2 s  .com*/

    g2d.fill(new Rectangle(20, 20, 200, 200));
    int red = 230;
    int green = 45;
    int blue = 67;
    g2d.setColor(new Color(red, green, blue));
    g2d.fill(new Rectangle(40, 40, 200, 200));
}

From source file:ColorUtil.java

/**
 * Blend two colors./*from w w  w  . ja  v  a 2 s. c o  m*/
 * 
 * @param color1  First color to blend.
 * @param color2  Second color to blend.
 * @param ratio   Blend ratio. 0.5 will give even blend, 1.0 will return
 *                color1, 0.0 will return color2 and so on.
 * @return        Blended color.
 */
public static Color blend(Color color1, Color color2, double ratio) {
    float r = (float) ratio;
    float ir = (float) 1.0 - r;

    float rgb1[] = new float[3];
    float rgb2[] = new float[3];

    color1.getColorComponents(rgb1);
    color2.getColorComponents(rgb2);

    Color color = new Color(rgb1[0] * r + rgb2[0] * ir, rgb1[1] * r + rgb2[1] * ir, rgb1[2] * r + rgb2[2] * ir);

    return color;
}

From source file:lu.lippmann.cdb.graph.renderer.CadralEdgeColorTransformer.java

private static Color rangeColor(Color colorMin, Color colorMax, BigDecimal grow, BigDecimal minValue,
        BigDecimal maxValue) {/*  w w  w  . j  ava  2 s.co  m*/
    BigDecimal colorValue = grow;
    if (colorValue == null) {
        return Color.LIGHT_GRAY;
    }

    if (maxValue.compareTo(minValue) < 0) {
        return rangeColor(colorMin, colorMax, grow, maxValue, minValue);
    } else {
        int rMax = colorMax.getRed();
        int gMax = colorMax.getGreen();
        int bMax = colorMax.getBlue();

        double color = 0.0;

        color = 255.0
                - grow.subtract(minValue).doubleValue() * 255.0 / maxValue.subtract(minValue).doubleValue();

        int r = rMax + (int) ((255 - rMax) * color / 255.0);
        int g = gMax + (int) ((255 - gMax) * color / 255.0);
        int b = bMax + (int) ((255 - bMax) * color / 255.0);

        if (r > 192 && g > 192 && b > 192)
            return Color.LIGHT_GRAY;

        return new Color(r, g, b);
    }

}

From source file:org.jfree.chart.demo.LeftPanel.java

public LeftPanel(ArrayList<ChartPanel> graphics, ArrayList<Graphic> Grafs, ArrayList<JFreeChart> charts,
        ArrayList<XYSeries> Series) {
    //setBackground(new Color(152 ,134, 202));
    //setBackground(new Color(234 ,247, 202));
    setSize(800, 530);/*from w ww  . ja  v  a 2  s  .  c  o m*/
    setLayout(null);
    setBackground(new Color(176, 199, 246));

    JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
    tabbedPane.setBackground(new Color(174, 250, 127));

    tabbedPane.setFont(new Font("Arial", 15, 16));
    tabbedPane.setOpaque(false);

    tabbedPane.setBounds(7, 6, 750, 505);
    tabbedPane.setAlignmentY(Component.TOP_ALIGNMENT);
    add(tabbedPane);

    JPanel panel = new JPanel();
    panel.setBackground(new Color(176, 199, 246));
    panel.setToolTipText("Graphic 1");
    panel.add(graphics.get(0));
    panel.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(0), 0));
    tabbedPane.addTab("Graphic 1", null, panel, null);
    panel.setLayout(null);

    JPanel panel_2 = new JPanel();
    panel_2.add(graphics.get(1));
    tabbedPane.addTab("Graphic 2", null, panel_2, null);
    panel_2.setLayout(null);
    panel_2.setBackground(new Color(176, 199, 246));
    panel_2.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(1), 1));

    JPanel panel_1 = new JPanel();
    panel_1.add(graphics.get(2));
    tabbedPane.addTab("Graphic 3", null, panel_1, null);
    panel_1.setLayout(null);
    panel_1.setBackground(new Color(176, 199, 246));
    panel_1.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(2), 2));
    panel_1.setBackground(new Color(176, 199, 246));

    JPanel panel_3 = new JPanel();
    panel_3.add(graphics.get(3));
    tabbedPane.addTab("Graphic 4", null, panel_3, null);
    panel_3.setLayout(null);
    panel_3.setBackground(new Color(176, 199, 246));
    panel_3.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(3), 3));

    JPanel panel_4 = new JPanel();
    panel_4.add(graphics.get(4));
    tabbedPane.addTab("Graphic 5 ", null, panel_4, null);
    panel_4.setLayout(null);
    panel_4.setBackground(new Color(176, 199, 246));
    panel_4.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(4), 4));

    JPanel panel_5 = new JPanel();
    panel_5.add(graphics.get(5));
    tabbedPane.addTab("Graphic 6", null, panel_5, null);
    panel_5.setLayout(null);
    panel_5.setBackground(new Color(176, 199, 246));
    panel_5.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(5), 5));

    JPanel panel_6 = new JPanel();
    panel_6.add(graphics.get(6));
    tabbedPane.addTab("Graphic 7", null, panel_6, null);
    panel_6.setLayout(null);
    panel_6.setBackground(new Color(176, 199, 246));
    panel_6.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(6), 6));

    JPanel panel_7 = new JPanel();
    panel_7.add(graphics.get(7));
    tabbedPane.addTab("Graphic 8", null, panel_7, null);
    panel_7.setLayout(null);
    panel_7.setBackground(new Color(176, 199, 246));
    panel_7.add(new bottom_slider(new Color(176, 199, 246), charts, Grafs.get(7), 7));

    JPanel panel_8 = new JPanel();
    panel_8.add(new Bottom_panel(Grafs, Series, 5, 390, 735, 50));
    graphics.set(8, Grafs.get(8).get_ChartPanel(740, 390));
    panel_8.add(graphics.get(8));

    tabbedPane.addTab("Graphic 9", null, panel_8, null);
    panel_8.setLayout(null);
    panel_8.setBackground(new Color(176, 199, 246));

    JPanel panel_9 = new JPanel();
    panel_9.add(graphics.get(9));
    tabbedPane.addTab("Graphic 10", null, panel_9, null);
    panel_9.setLayout(null);
    panel_9.setBackground(new Color(176, 199, 246));

}

From source file:org.jfree.chart.demo.LineChart3DDemo1.java

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createLineChart3D("Line Chart 3D Demo 1", null, "Class Count",
            categorydataset, PlotOrientation.VERTICAL, false, true, false);
    jfreechart.setBackgroundPaint(new Color(187, 187, 221));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setAutoRangeIncludesZero(false);
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    return jfreechart;
}

From source file:Main.java

public Main() {
    setSize(300, 100);//from w  w w.  j  av  a2  s.  co m

    UIManager.put("ProgressBar.selectionBackground", Color.black);
    UIManager.put("ProgressBar.selectionForeground", Color.white);
    UIManager.put("ProgressBar.foreground", new Color(8, 32, 128));

    progressBar = new JProgressBar();
    progressBar.setMinimum(minValue);
    progressBar.setMaximum(maxValue);
    progressBar.setStringPainted(true);

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Thread runner = new Thread() {
                public void run() {
                    counter = minValue;
                    while (counter <= maxValue) {
                        Runnable runme = new Runnable() {
                            public void run() {
                                progressBar.setValue(counter);
                            }
                        };
                        SwingUtilities.invokeLater(runme);
                        counter++;
                        try {
                            Thread.sleep(100);
                        } catch (Exception ex) {
                        }
                    }
                }
            };
            runner.start();
        }
    });

    getContentPane().add(progressBar, BorderLayout.CENTER);
    getContentPane().add(start, BorderLayout.WEST);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:JProgressBarDemo.java

public JProgressBarDemo() {
    super("JProgressBar Demo");
    setSize(300, 100);/*www . ja va 2  s.  c  om*/

    UIManager.put("ProgressBar.selectionBackground", Color.black);
    UIManager.put("ProgressBar.selectionForeground", Color.white);
    UIManager.put("ProgressBar.foreground", new Color(8, 32, 128));

    progressBar = new JProgressBar();
    progressBar.setMinimum(minValue);
    progressBar.setMaximum(maxValue);
    progressBar.setStringPainted(true);

    JButton start = new JButton("Start");
    start.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Thread runner = new Thread() {
                public void run() {
                    counter = minValue;
                    while (counter <= maxValue) {
                        Runnable runme = new Runnable() {
                            public void run() {
                                progressBar.setValue(counter);
                            }
                        };
                        SwingUtilities.invokeLater(runme);
                        counter++;
                        try {
                            Thread.sleep(100);
                        } catch (Exception ex) {
                        }
                    }
                }
            };
            runner.start();
        }
    });

    getContentPane().add(progressBar, BorderLayout.CENTER);
    getContentPane().add(start, BorderLayout.WEST);

    WindowListener wndCloser = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };
    addWindowListener(wndCloser);
    setVisible(true);
}

From source file:Demo14.java

public Demo14(int nDiscs) {
    super("G Graphics Library - Demo 14");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    nDiscs_ = nDiscs;/*from w  ww . j a va2  s.com*/

    // Create the graphic canvas
    window_ = new GWindow(new Color(200, 230, 200));
    getContentPane().add(window_.getCanvas());

    // Create scene
    GScene scene = new GScene(window_);
    double w0[] = { 0.0, 0.0, 0.0 };
    double w1[] = { 4.0, 0.0, 0.0 };
    double w2[] = { 0.0, nDiscs_ * 2, 0.0 };
    scene.setWorldExtent(w0, w1, w2);

    // Add title object and add to scene
    scene.add(new Title());

    // Create the 3 pegs and add to the scene
    int nPegs = 3;
    pegs_ = new Peg[nPegs];
    for (int i = 0; i < nPegs; i++) {
        pegs_[i] = new Peg(i + 1.0);
        scene.add(pegs_[i]);
    }

    // Create the discs and add to the first peg
    for (int i = 0; i < nDiscs; i++) {
        Disc disc = new Disc((double) (nDiscs - i) / nDiscs);
        disc.setPosition(1.0, i);
        pegs_[0].add(disc);
    }

    pack();
    setSize(new Dimension(500, 500));
    setVisible(true);

    // Create the puzzle and execute the solution
    towersOfHanoi_ = new TowersOfHanoi();
    towersOfHanoi_.solve();
}

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    super("Custom MDI: Part II");
    setSize(570, 400);//  w  ww  . j  a v a2  s  . co m
    getContentPane().setBackground(new Color(244, 232, 152));

    getLayeredPane().setOpaque(true);

    InnerFrame[] frames = new InnerFrame[5];
    for (int i = 0; i < 5; i++) {
        frames[i] = new InnerFrame("InnerFrame " + i);
        frames[i].setBounds(50 + i * 20, 50 + i * 20, 200, 200);
        getLayeredPane().add(frames[i]);
    }

    WindowListener l = new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
        }
    };

    Dimension dim = getToolkit().getScreenSize();
    setLocation(dim.width / 2 - getWidth() / 2, dim.height / 2 - getHeight() / 2);

    ImageIcon image = new ImageIcon("spiral.gif");
    setIconImage(image.getImage());
    addWindowListener(l);
    setVisible(true);
}