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:Rectangles.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(212, 212, 212));
    g2d.drawRect(10, 15, 90, 60);/*from w  ww .j  a  v a2s . c  om*/

    g2d.setColor(new Color(31, 21, 1));
    g2d.fillRect(250, 195, 90, 60);

}

From source file:Util.java

/**
* Return a <code>Color</code> object given a string representation of it
*
* @param color/*from  w w  w.  j  av  a  2 s.  c  o  m*/
* @return string representation
* @throws IllegalArgumentException if string in bad format
*/
public static Color stringToColor(String s) {
    try {
        return new Color(Integer.decode("0x" + s.substring(1, 3)).intValue(),
                Integer.decode("0x" + s.substring(3, 5)).intValue(),
                Integer.decode("0x" + s.substring(5, 7)).intValue());
    } catch (Exception e) {
        return null;
    }
}

From source file:Scale.java

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

    g2d.setColor(new Color(150, 150, 150));
    g2d.fillRect(0, 0, 80, 50);/*from ww w.  j ava  2 s.co  m*/

    AffineTransform tx1 = new AffineTransform();
    tx1.translate(110, 20);
    tx1.scale(0.5, 0.5);

    g2d.setTransform(tx1);
    g2d.fillRect(0, 0, 80, 50);

    AffineTransform tx2 = new AffineTransform();
    tx2.translate(200, 20);
    tx2.scale(1.5, 1.5);

    g2d.setTransform(tx2);
    g2d.fillRect(0, 0, 80, 50);

}

From source file:Colors.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(12, 16, 116));
    g2d.fillRect(10, 15, 90, 60);/* w w w  . j  av  a2 s  . co m*/

    g2d.setColor(new Color(42, 19, 31));
    g2d.fillRect(130, 15, 90, 60);

    g2d.setColor(new Color(70, 7, 23));
    g2d.fillRect(250, 15, 90, 60);

    g2d.setColor(new Color(10, 10, 84));
    g2d.fillRect(10, 105, 90, 60);

    g2d.setColor(new Color(22, 21, 61));
    g2d.fillRect(130, 105, 90, 60);

    g2d.setColor(new Color(21, 98, 69));
    g2d.fillRect(250, 105, 90, 60);

    g2d.setColor(new Color(217, 146, 54));
    g2d.fillRect(10, 195, 90, 60);

    g2d.setColor(new Color(63, 121, 186));
    g2d.fillRect(130, 195, 90, 60);

    g2d.setColor(new Color(131, 121, 11));
    g2d.fillRect(250, 195, 90, 60);

}

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    super("");
    setSize(570, 400);//from w w w.jav a  2s. c o  m
    getContentPane().setBackground(new Color(244, 232, 152));

    getLayeredPane().setOpaque(true);

    JButton[] frames = new JButton[5];
    for (int i = 0; i < 5; i++) {
        frames[i] = new JButton("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);
        }
    };

    addWindowListener(l);
    setVisible(true);
}

From source file:ColorVariousObjects.java

public void paint(Graphics g) {
    Color c1 = new Color(255, 100, 100);
    Color c2 = new Color(100, 255, 100);
    Color c3 = new Color(100, 100, 255);

    g.setColor(c1);//from w w w.ja v a2s .  c o  m
    g.drawLine(0, 0, 100, 100);
    g.drawLine(0, 100, 100, 0);

    g.setColor(c2);
    g.drawLine(40, 25, 250, 180);
    g.drawLine(75, 90, 400, 400);

    g.setColor(c3);
    g.drawLine(20, 150, 400, 40);
    g.drawLine(5, 290, 80, 19);

    g.setColor(Color.red);
    g.drawOval(10, 10, 50, 50);
    g.fillOval(70, 90, 140, 100);

    g.setColor(Color.blue);
    g.drawOval(190, 10, 90, 30);
    g.drawRect(10, 10, 60, 50);

    g.setColor(Color.cyan);
    g.fillRect(100, 10, 60, 50);
    g.drawRoundRect(190, 10, 60, 50, 15, 15);
}

From source file:GuiUtil.java

public static Color cloneColor(Color c) {
    return new Color(c.getRed(), c.getGreen(), c.getBlue());
}

From source file:Textures.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(212, 212, 212));
    g2d.drawRect(10, 15, 90, 60);/*from   w  ww.ja  v  a2  s.c o m*/

    BufferedImage bimage1 = null;

    URL url1 = ClassLoader.getSystemResource("a.png");

    try {
        bimage1 = ImageIO.read(url1);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    Rectangle rect1 = new Rectangle(0, 0, bimage1.getWidth(), bimage1.getHeight());
    TexturePaint texture1 = new TexturePaint(bimage1, rect1);

    g2d.setPaint(texture1);
    g2d.fillRect(10, 15, 90, 60);
}

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

private static JFreeChart createChart(CategoryDataset categorydataset) {
    JFreeChart jfreechart = ChartFactory.createBarChart("Event Frequency Demo", "Category", "Value",
            categorydataset, PlotOrientation.HORIZONTAL, true, true, false);
    jfreechart.setBackgroundPaint(new Color(255, 255, 204));
    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.getDomainAxis().setMaximumCategoryLabelWidthRatio(10F);
    categoryplot.setRangeAxis(new DateAxis("Date"));
    StandardCategoryToolTipGenerator standardcategorytooltipgenerator = new StandardCategoryToolTipGenerator("",
            DateFormat.getDateInstance());
    LineAndShapeRenderer lineandshaperenderer = new LineAndShapeRenderer(false, true);
    lineandshaperenderer.setBaseToolTipGenerator(standardcategorytooltipgenerator);
    categoryplot.setRenderer(lineandshaperenderer);
    return jfreechart;
}

From source file:PaintUtils.java

/** @return the color used to indicate when a component has
 * focus.  By default this uses the color (64,113,167), but you can
 * override this by calling://  w ww  . jav  a  2 s .c  o  m
 * <BR><code>UIManager.put("focusRing",customColor);</code>
 */
public static Color getFocusRingColor() {
    Object obj = UIManager.getColor("focusRing");
    if (obj instanceof Color)
        return (Color) obj;
    return new Color(64, 113, 167);
}