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

public static void main(String[] a) {
    Color myBlack = new Color(0, 0, 0); // Color black
    Color myWhite = new Color(255, 255, 255); // Color white
    System.out.println(myBlack.equals(myWhite));
}

From source file:Main.java

public static void main(String[] args) {

    Color myColor = new Color(ColorSpace.getInstance(ColorSpace.CS_CIEXYZ), new float[] { 0.1F, 0.2F, 0.3F },
            0.4F);//from  w w  w  .  j  ava  2  s.co m

    System.out.println(Arrays.toString(myColor.getColorComponents(null)));

}

From source file:Main.java

public static void main(String[] args) {
    Color myColor = new Color(0.1F, 0.2F, 0.3F);

    JLabel label = new JLabel("First Name");
    label.setForeground(myColor);/* www . j a va2s . c  o m*/

    JFrame frame = new JFrame();
    frame.add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {
    Color myBlack = new Color(0, 0, 0); // Color black
    //  Color myWhite = new Color(255,255,255);     // Color white
    //  Color myGreen = new Color(0,200,0);         // A shade of green

    JLabel label = new JLabel("First Name");
    label.setForeground(myBlack);/*  ww w  .  j  a  v a 2s . c  o  m*/

    JFrame frame = new JFrame();
    frame.add(label);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setBounds(20, 20, 500, 500);
    frame.setVisible(true);

}

From source file:Main.java

public static void main(String[] args) {

    JLabel label = new JLabel("Full Name :", JLabel.LEFT);

    label.setOpaque(true);/*from  w w  w.ja  va  2 s .c  o m*/
    label.setForeground(new Color(150, 150, 25));
    label.setBackground(new Color(50, 50, 25));

    JOptionPane.showMessageDialog(null, label);

}

From source file:Main.java

public static void main(String args[]) {
    JFrame f = new JFrame("JColorChooser Sample");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    final JButton button = new JButton("Pick to Change Background");
    Color myBlack = new Color(0, 0, 0); // Color black
    //    Color myWhite = new Color(255,255,255);     // Color white
    //  Color myGreen = new Color(0,200,0);         // A shade of green

    button.setBackground(myBlack);/*  w w w .j  a v  a  2  s .c  o  m*/
    f.add(button, BorderLayout.CENTER);
    f.setSize(300, 200);
    f.setVisible(true);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Rectangle r = new Rectangle(PageSize.A4);
    r.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    Document document = new Document(r);
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//w  w w .j  av a  2 s  .c  o m
    java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("dog.gif");
    com.lowagie.text.Image img1 = com.lowagie.text.Image.getInstance(awtImage, null, true);
    document.add(img1);

    document.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Rectangle r = new Rectangle(PageSize.A4);
    r.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    Document document = new Document(r);
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//w  w  w  .  java 2 s.c om
    java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("dog.gif");
    com.lowagie.text.Image img1 = com.lowagie.text.Image.getInstance(awtImage, null);
    document.add(img1);

    document.close();
}

From source file:Main.java

public static void main(String[] args) {
    byte ff = (byte) 0xff;
    byte[] r = { ff, 0, 0, ff, 0 };
    byte[] g = { 0, ff, 0, ff, 0 };
    byte[] b = { 0, 0, ff, ff, 0 };

    ColorModel cm = new IndexColorModel(3, 5, r, g, b);

    Color[] colors = { new Color(255, 0, 0), new Color(0, 255, 0), new Color(0, 0, 255), new Color(64, 255, 64),
            new Color(255, 255, 0), new Color(0, 255, 255) };

    for (int i = 0; i < colors.length; i++) {
        float[] normalizedComponents = colors[i].getComponents(null);
        int[] unnormalizedComponents = cm.getUnnormalizedComponents(normalizedComponents, 0, null, 0);
        int rgb = colors[i].getRGB();
        Object pixel = cm.getDataElements(rgb, null);
        System.out.println(colors[i] + " -> " + ((byte[]) pixel)[0]);
    }//from  w  w  w  .  ja  v  a2 s  .  c  om

    for (byte i = 0; i < 5; i++) {
        int[] unnormalizedComponents = cm.getComponents(i, null, 0);
        System.out.print(i + " -> unnormalized components");
        for (int j = 0; j < unnormalizedComponents.length; j++)
            System.out.print(" " + unnormalizedComponents[j]);
        System.out.println();
    }
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Rectangle r = new Rectangle(PageSize.A4);
    r.setBackgroundColor(new Color(0xC0, 0xC0, 0xC0));
    Document document = new Document(r);
    PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//  w ww  . j a v  a  2s .c  o  m
    java.awt.Image awtImage = Toolkit.getDefaultToolkit().createImage("dog.gif");
    com.lowagie.text.Image img1 = com.lowagie.text.Image.getInstance(awtImage, new Color(0xFF, 0xFF, 0x00));
    document.add(img1);

    document.close();
}