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

private Color randomColor() {
    int r = (int) (255 * Math.random());
    int g = (int) (255 * Math.random());
    int b = (int) (255 * Math.random());
    return new Color(r, g, b);
}

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

public RightPanel(int x, int y, int width, int height, String baude[], String name[]) {

    setBackground(new Color(176, 199, 246));

    this.width = width;
    this.height = height;

    Data[0] = "8";
    Data[1] = "9";

    Name = name;/* w w w. j av a2  s .  c  o  m*/
    Baude = baude;

    setLayout(new GridLayout(8, 1, 0, 0));

    lblName = new JLabel("Name");
    lblName.setHorizontalAlignment(SwingConstants.CENTER);
    lblName.setFont(new Font("Arial", 15, 16));
    add(lblName);

    comboBox = new JComboBox(Name);
    comboBox.setFont(new Font("Arial", 15, 16));
    add(comboBox);

    JLabel lblBaude = new JLabel("Baude");
    lblBaude.setFont(new Font("Arial", 15, 16));
    lblBaude.setHorizontalAlignment(SwingConstants.CENTER);
    add(lblBaude);

    final JComboBox comboBox_1 = new JComboBox(Baude);
    comboBox_1.setFont(new Font("Arial", 15, 16));
    add(comboBox_1);

    JLabel lblDataSize = new JLabel("Data size");
    lblDataSize.setHorizontalAlignment(SwingConstants.CENTER);
    lblDataSize.setFont(new Font("Arial", 15, 16));
    add(lblDataSize);

    final JComboBox comboBox_2 = new JComboBox(Data);
    comboBox_2.setFont(new Font("Arial", 15, 16));
    add(comboBox_2);

    JSeparator separator = new JSeparator();
    add(separator);

    btnOpen = new JButton("Open");
    btnOpen.setFont(new Font("Arial", 15, 16));
    btnOpen.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (btnOpen.getText() == "Open") {
                btnOpen.setText("Close");
                open = true;
                int baude = 9600, data = 8;
                try {
                    baude = Integer.parseInt((String) comboBox_1.getSelectedItem());
                    data = Integer.parseInt((String) comboBox_2.getSelectedItem());
                } catch (Exception e) {
                    errors += "Enter correct Bauderate\n";
                    error_flag = true;

                }
                comport = new Comport((String) comboBox.getSelectedItem(), baude, data);
                comport.start();

            } else {
                comport.flag = false;
                btnOpen.setText("Open");
                open = false;

                comport.close();
                //   comport.stop();

                System.out.println("Comport = " + comport.isAlive());
                System.out.println("Comport life  = " + comport.get_life());

            }
        }
    });
    add(btnOpen);
    setBounds(x + 50, y, width - 40, height - 20);
    err.setBounds(x + 50, y, 50, 50);
    //add(err);

}

From source file:ImageProc.java

public static void imagesc(File file, int[][] classificationMat, int nClass, int imgDim1, int imgDim2) {
    BufferedImage image = new BufferedImage(imgDim2, imgDim1, BufferedImage.TYPE_INT_RGB);
    int index, rgb;
    float[][] jet = colormapJet(nClass);
    for (int i = 0; i < imgDim1; i++) {
        for (int j = 0; j < imgDim2; j++) {
            index = classificationMat[i][j];
            if (index == -1) {
                image.setRGB(j, i, Color.BLACK.getRGB());
            } else {
                rgb = new Color(jet[index][0], jet[index][1], jet[index][2]).getRGB();
                image.setRGB(j, i, rgb);
            }/*  w w w. ja  v a  2  s. com*/
        }
    }
    try {
        ImageIO.write(image, "png", file);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:LayeredPaneDemo3.java

public LayeredPaneDemo3() {
    super("Custom MDI: Part IV");
    setSize(570, 400);/*from  ww w  .j ava2  s.  c  o  m*/
    getContentPane().setBackground(new Color(244, 232, 152));

    setLayeredPane(new MDIPane());

    ImageIcon ii = new ImageIcon("earth.jpg");
    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);
        frames[i].getContentPane().add(new JScrollPane(new JLabel(ii)));
        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);
}

From source file:components.TopLevelDemo.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread./* w w w. j a  v a2  s .c om*/
 */
private static void createAndShowGUI() {
    //Create and set up the window.
    JFrame frame = new JFrame("TopLevelDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create the menu bar.  Make it have a green background.
    JMenuBar greenMenuBar = new JMenuBar();
    greenMenuBar.setOpaque(true);
    greenMenuBar.setBackground(new Color(154, 165, 127));
    greenMenuBar.setPreferredSize(new Dimension(200, 20));

    //Create a yellow label to put in the content pane.
    JLabel yellowLabel = new JLabel();
    yellowLabel.setOpaque(true);
    yellowLabel.setBackground(new Color(248, 213, 131));
    yellowLabel.setPreferredSize(new Dimension(200, 180));

    //Set the menu bar and add the label to the content pane.
    frame.setJMenuBar(greenMenuBar);
    frame.getContentPane().add(yellowLabel, BorderLayout.CENTER);

    //Display the window.
    frame.pack();
    frame.setVisible(true);
}

From source file:forge.gui.CardDetailPanel.java

private static Color fromDetailColor(final DetailColors detailColor) {
    return new Color(detailColor.r, detailColor.g, detailColor.b);
}

From source file:Containers.java

public Containers() {
    this.setBackground(Color.white); // This component is white
    this.setFont(new Font("Dialog", Font.BOLD, 24));

    JPanel p1 = new JPanel();
    p1.setBackground(new Color(200, 200, 200)); // Panel1 is darker
    this.add(p1); // p1 is contained by this component
    p1.add(new JButton("#1")); // Button 1 is contained in p1

    JPanel p2 = new JPanel();
    p2.setBackground(new Color(150, 150, 150)); // p2 is darker than p2
    p1.add(p2); // p2 is contained in p1
    p2.add(new JButton("#2")); // Button 2 is contained in p2

    JPanel p3 = new JPanel();
    p3.setBackground(new Color(100, 100, 100)); // p3 is darker than p2
    p2.add(p3); // p3 is contained in p2
    p3.add(new JButton("#3")); // Button 3 is contained in p3

    JPanel p4 = new JPanel();
    p4.setBackground(new Color(150, 150, 150)); // p4 is darker than p1
    p1.add(p4); // p4 is contained in p1
    p4.add(new JButton("#4")); // Button4 is contained in p4
    p4.add(new JButton("#5")); // Button5 is also contained in p4

    this.add(new JButton("#6")); // Button6 is contained in this component
}

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    super("");
    setSize(570, 400);//  w w  w  . j  a va2  s .  c  o  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);
        }
    };

    addWindowListener(l);
    setVisible(true);
}

From source file:LayeredPaneDemo4.java

public LayeredPaneDemo4() {
    super("Custom MDI: Part V");
    setSize(570, 400);//from  www . j av  a  2  s. c  o m
    getContentPane().setBackground(new Color(244, 232, 152));

    setLayeredPane(new MDIPane());

    ImageIcon ii = new ImageIcon("earth.jpg");
    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);
        frames[i].getContentPane().add(new JScrollPane(new JLabel(ii)));
        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);
}

From source file:Componentes.TermometroMax.java

@Override
public void pintar(javax.swing.JPanel p, int pos) {
    p.removeAll();/*ww  w .j a v  a  2  s .  c o m*/
    DefaultValueDataset data = new DefaultValueDataset(new Double(ventana.getGraphdata().getTmax()));

    ThermometerPlot plot = new ThermometerPlot(data);
    chart = new JFreeChart("Temperatura Maxima, \nMES: " + Calculos.get_mes(ventana.getMonthdata().getdata()), // chart title
            JFreeChart.DEFAULT_TITLE_FONT, plot, // plot
            false);

    Color Darkorange = new Color(255, 140, 0);
    Color Crimson = new Color(220, 20, 60);
    Color Aquamarine = new Color(127, 255, 212);
    Color Darkslategray = new Color(47, 79, 79);

    plot.setMercuryPaint(Aquamarine);
    plot.setSubrange(NORMAL, 0, 10);
    plot.setSubrange(WARNING, 10.1, 20);
    plot.setSubrange(CRITICAL, 20.1, 50);
    plot.setSubrangePaint(NORMAL, Aquamarine);
    plot.setSubrangePaint(WARNING, Darkorange);
    plot.setSubrangePaint(CRITICAL, Crimson);

    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Darkslategray);

    plot.setDisplayRange(5, Calculos.get_min(datos.getTmax()), Calculos.get_max(datos.getTmax()));
    plot.setRange(Calculos.get_min(datos.getTmax()), Calculos.get_max(datos.getTmax()));

    panel = new ChartPanel(chart);
    panel.setBounds(5, 5, 300, 300);
    panel.repaint();
    p.add(panel);
    // jPanel1.repaint();
    p.updateUI();
    // aoIndex=aoAux;
    ///aoAux = 0;
}