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(int rgb) 

Source Link

Document

Creates an opaque sRGB color with the specified combined RGB value consisting of the red component in bits 16-23, the green component in bits 8-15, and the blue component in bits 0-7.

Usage

From source file:Main.java

public static void main(String[] args) {
    Color myColor = new Color(0XFFFFFF);

    JLabel label = new JLabel("First Name");
    label.setForeground(myColor);/*from  ww w  . j  a  v  a 2  s.co 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:fr.romainf.QRCode.java

public static void main(String[] args) {
    Options options = buildOptions();/*from w  w w . j a v  a  2 s  .  c  om*/

    CommandLineParser parser = new BasicParser();

    try {
        CommandLine cmd = parser.parse(options, args);
        args = cmd.getArgs();

        int l = args.length;
        if (l != 1) {
            System.out.println("Can only encode one datum at a time (" + l + " given)");
            printUsage(options);
            System.exit(1);
        }
        if (cmd.hasOption("help")) {
            printUsage(options);
            System.exit(0);
        }

        String output = cmd.getOptionValue("o", DEFAULT_OUTPUT_FILE);
        String pixelColourText = cmd.getOptionValue("c", DEFAULT_PIXEL_COLOUR);
        if (pixelColourText.startsWith("0x")) {
            pixelColourText = pixelColourText.substring(2);
        }
        Color pixelColour;
        if (pixelColourText.length() == 6) {
            pixelColour = new Color(Integer.parseInt(pixelColourText, 16));
        } else {
            pixelColour = new Color((int) Long.parseLong(pixelColourText, 16), true);
        }

        writeQRCode(args[l - 1], output, pixelColour);

    } catch (ParseException e) {
        System.out.println(e.getMessage());
        printUsage(options);
        System.exit(1);
    } catch (WriterException e) {
        System.out.println("Could not create QRCode from data (" + e.getMessage() + ")");
        System.exit(2);
    } catch (IOException e) {
        System.out.println("Could not save QRCode to file (" + e.getMessage() + ")");
        System.exit(4);
    }
    System.exit(0);
}

From source file:ec.util.chart.swing.JTimeSeriesRendererSupportDemo.java

public static void main(String[] args) {
    new BasicSwingLauncher().content(JTimeSeriesRendererSupportDemo.class).title("Support Demo")
            .icons(new Callable<List<Image>>() {
                @Override//w  w w  .j a v a 2 s  .c o  m
                public List<Image> call() throws Exception {
                    Color c = new Color(TangoColorScheme.DARK_SKY_BLUE);
                    return FontAwesome.FA_TACHOMETER.getImages(c, 16f, 32f, 64f);
                }
            }).launch();
}

From source file:main.java.whiteSocket.Bloop.java

public static void main(String[] args) throws Exception {

    System.out.println(//from  w ww  .  jav a  2 s  .c  om
            "****************\n****************\n\nYou are using Blooprint \u00ae software.\n\nPlease refer to our license here:\nhttp://github.com/blooprint/whiteSocket/blob/master/LICENSE\n\n****************");

    title = args[0];

    jarMode = (args[4].toLowerCase().equals("true") ? true : false);

    if (jarMode) {
        System.out.println("\nwhiteSocket: PRODUCTION EXECUTABLE/JAR MODE\n");
        sketchFile = "/input/" + args[0] + ".bmp";
        blooprintFile = "/output/" + args[1] + ".bmp";
    } else {
        System.out.println("\nwhiteSocket: DEVELOPMENT MODE\n");
        sketchFile = "./io/input/" + args[0] + ".bmp";
        blooprintFile = "./io/output/" + args[1] + ".bmp";
    }

    inMode = args[2];

    markerHex = Integer.parseInt(args[3], 16);
    System.out.println("marker decimal value = " + markerHex);

    if (args[1] != null)
        blooprint = loadBlooprint();
    sketch = loadSketch();

    brightThreshold = getBrightnessThreshold();

    switch (inMode) {

    case "write":
        calibrate();
        write();
        saveBlooprint();
        break;

    case "erase":
        calibrate();

        eraseAreas = new ArrayList<Area>();
        Area.totalErase = new boolean[sketch.getHeight()][sketch.getWidth()];

        Color pxColor = null;
        for (int row = 0; row < sketch.getHeight(); row++) {
            for (int col = 0; col < sketch.getWidth(); col++) {

                pxColor = new Color(sketch.getRGB(col, row));
                /*
                 * TODO:
                 * !totalErase[][] - to make sure the pixel isn't yet considered as an eraser pixel
                 * */
                if (areaOfInterest[row][col] && isMarker(pxColor) && !Area.totalErase[row][col]) {
                    eraseAreas.add(new Area(col, row));
                }
            }
        }

        for (Area some : eraseAreas) {
            erase(some.area);
        }

        saveBlooprint();
        break;

    default:
        break;
    }

    System.exit(0);

}

From source file:Main.java

public static Color getColorFromString(String colorStr) {
    return new Color(Integer.parseInt(colorStr));
}

From source file:Main.java

public static Color fixSeveralColorRenderingIssues(Color color) {
    return new Color(color.getRGB());
}

From source file:Main.java

public static Color parseToColor(String rgbString) {
    if (rgbString == null)
        return null;
    int rgb = Integer.valueOf(rgbString);
    return new Color(rgb);
}

From source file:Main.java

/**
 * Parse string value as Color. Return default value if source
 * string is null./*  www.ja  v  a2s  .  c om*/
 * @param value String
 * @param defValue int - color value in RGB
 * @return Color
 */
public static Color getAsColor(String value, int defValue) {
    Color result = new Color(defValue);
    if (value != null) {
        try {
            result = new Color(Integer.parseInt(value, 16));
        } catch (NumberFormatException ex) {
        }
    }
    return result;
}

From source file:Main.java

public static byte[] getCompressedImage(byte[] rgb) {

    BufferedImage image;// w w  w  .  j av a  2  s. c  o m
    int width;
    int height;

    try {
        image = ImageIO.read(new ByteArrayInputStream(rgb));
        width = image.getWidth();
        height = image.getHeight();

        for (int i = 0; i < height; i++) {

            for (int j = 0; j < width; j++) {

                Color c = new Color(image.getRGB(j, i));
                int red = (int) (c.getRed() * 0.299);
                int green = (int) (c.getGreen() * 0.587);
                int blue = (int) (c.getBlue() * 0.114);
                Color newColor = new Color(red + green + blue,

                        red + green + blue, red + green + blue);

                image.setRGB(j, i, newColor.getRGB());
            }
        }

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ImageIO.write(image, "jpg", baos);
        baos.flush();
        byte[] imageInByte = baos.toByteArray();
        baos.close();

        return imageInByte;

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static Color convertHexStringToColor(String str) throws NumberFormatException {
    int multiplier = 1;
    StringTokenizer tokenizer = new StringTokenizer(str, " \t\r\n\b:;[]()+");
    while (tokenizer.hasMoreTokens()) {
        multiplier = 1;//from w w w .j  a  va2 s .c o m
        String token = tokenizer.nextToken();
        if (null == token) {
            throw new NumberFormatException(str);
        }
        if (token.startsWith("-")) {
            multiplier = -1;
            token = token.substring(1);
        }
        int point_index = token.indexOf(".");
        if (point_index > 0) {
            token = token.substring(0, point_index);
        } else if (point_index == 0) {
            return new Color(0);
        }
        try {
            if (token.startsWith("0x")) {
                return new Color(multiplier * Integer.parseInt(token.substring(2), 16));
            } else if (token.startsWith("#")) {
                return new Color(multiplier * Integer.parseInt(token.substring(1), 16));
            } else if (token.startsWith("0") && !token.equals("0")) {
                return new Color(multiplier * Integer.parseInt(token.substring(1), 8));
            } else {
                return new Color(multiplier * Integer.parseInt(token));
            }
        } catch (NumberFormatException e) {
            continue;
        }
    }
    throw new NumberFormatException(str);

}