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 rgba, boolean hasalpha) 

Source Link

Document

Creates an sRGB color with the specified combined RGBA value consisting of the alpha component in bits 24-31, 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(0XFFFFFFFF, true);

    JLabel label = new JLabel("First Name");
    label.setForeground(myColor);/*ww w .j  a  va  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:Main.java

public static void main(String[] args) throws Exception {
    BufferedImage inputFile = ImageIO.read(new URL("http://www.java2s.com/style/download.png"));

    for (int x = 0; x < inputFile.getWidth(); x++) {
        for (int y = 0; y < inputFile.getHeight(); y++) {
            int rgba = inputFile.getRGB(x, y);
            Color col = new Color(rgba, true);
            col = new Color(255 - col.getRed(), 255 - col.getGreen(), 255 - col.getBlue());
            inputFile.setRGB(x, y, col.getRGB());
        }/*from ww w.  j  a v a  2  s.c  o m*/
    }

    File outputFile = new File("invert.png");
    ImageIO.write(inputFile, "png", outputFile);

}

From source file:Main.java

public static void main(String[] args) {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame f = new JFrame();
    f.setBackground(new Color(0, true)); // 1.7.0
    f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    f.getContentPane().add(makeUI());//from   w  w w .j  a v a 2 s .c  om
    f.setSize(320, 240);
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}

From source file:Main.java

public static Color readColorAttr(Element element, String attributeName, Color defaultValue) {
    String s = element.getAttribute(attributeName);

    if (s == null || s.charAt(0) != '#') {
        return defaultValue;
    }/*from w w  w.j  a  va  2  s .c  o m*/

    try {
        return new Color(Integer.parseInt(s.substring(1), 16), false);
    } catch (NumberFormatException e) {
        e.printStackTrace();
        return defaultValue;
    }
}

From source file:Main.java

private static Color getColorFromPallet(int[] pallet, float x) {
    if (x < 0.0 || x > 1.0) {
        throw new IllegalArgumentException("Parameter outside of expected range");
    }/*from w w  w  .  j  a v  a  2s . c  om*/
    int i = (int) (pallet.length * x);
    int max = pallet.length - 1;
    int index = i < 0 ? 0 : i > max ? max : i;
    int pix = pallet[index] & 0x00ffffff | (0x64 << 24);
    return new Color(pix, true);
}

From source file:ca.sqlpower.wabit.swingui.chart.WabitJFreeChartPanel.java

public WabitJFreeChartPanel(JFreeChart chart) {
    super(chart, false, false, false, false, false);
    setBackground(new Color(0, true));
}

From source file:tarea1.histogram.java

private ChartPanel createChartPanel() {
    // dataset//from   w  w  w .ja  va  2s . c om
    HistogramDataset dataset = new HistogramDataset();
    Raster raster = image.getRaster();
    final int w = image.getWidth();
    final int h = image.getHeight();
    double[] r = new double[w * h];
    r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, BINS);
    r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", r, BINS);
    r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", r, BINS);
    // chart
    JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    // translucent red, green & blue
    Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true),
            new Color(0x800000ff, true) };
    plot.setDrawingSupplier(
            new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    return panel;
}

From source file:com.igormaznitsa.sciareto.notifications.NotificationManager.java

public void showNotification(@Nullable final Image icon, @Nullable final String title, @Nonnull final Type type,
        @Nonnull final JComponent component) {
    Utils.safeSwingCall(new Runnable() {
        @Override//  w w  w  .j  a va  2  s.  c om
        public void run() {
            final JPanel stack = Main.getApplicationFrame().getStackPanel();

            Color color = Color.WHITE;
            switch (type) {
            case ERROR:
                color = new Color(0xFFCCCC, false);
                break;
            case WARN:
                color = new Color(0xFFFF99, false);
                break;
            case INFO:
                color = new Color(0xCCFFCC, false);
                break;
            }

            stack.add(new MessagePanel(icon, title, color, component), 0);
            stack.revalidate();
            Main.getApplicationFrame().getGlassPane().setVisible(true);
        }
    });
}

From source file:pdi.HistogramaRGB.java

public ChartPanel criaHistograma() {
    dataset = new HistogramDataset();
    //pega o RGB//w  ww . j  av  a 2s  .  c o  m
    r = raster.getSamples(0, 0, w, h, 0, r);
    dataset.addSeries("Red", r, BINS);
    r = raster.getSamples(0, 0, w, h, 1, r);
    dataset.addSeries("Green", r, BINS);
    r = raster.getSamples(0, 0, w, h, 2, r);
    dataset.addSeries("Blue", r, BINS);
    JFreeChart chart = ChartFactory.createHistogram("Histograma", "Pixels", "Y", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //Plota as cores
    XYPlot plot = (XYPlot) chart.getPlot();
    renderer = (XYBarRenderer) plot.getRenderer();
    renderer.setBarPainter(new StandardXYBarPainter());
    //vermelho, verde, azul
    Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true),
            new Color(0x800000ff, true) };
    //desenhando o grfico
    plot.setDrawingSupplier(
            new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
                    DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE));
    ChartPanel panel = new ChartPanel(chart);
    panel.setMouseWheelEnabled(true);
    return panel;
}

From source file:ImageProcessing.ImageProcessing.java

public static double[] extractAlphaValue(BufferedImage source) {
    //Extracts the Alpha value from the RGB value of the source pixels.
    int imageWidth = source.getWidth();
    int imageHeight = source.getHeight();
    double[] values = new double[imageWidth * imageHeight];

    for (int i = 0; i < imageHeight; i++) {
        for (int j = 0; j < imageWidth; j++) {
            int rgbValue = source.getRGB(j, i);
            Color currentPixel = new Color(rgbValue, true);
            int value = currentPixel.getAlpha();
            values[(i * imageWidth) + j] = value;
        }//from  w w  w  .  jav a2 s.c  o  m
    }

    return values;
}