Example usage for java.awt Color green

List of usage examples for java.awt Color green

Introduction

In this page you can find the example usage for java.awt Color green.

Prototype

Color green

To view the source code for java.awt Color green.

Click Source Link

Document

The color green.

Usage

From source file:Main.java

public Main() {
    JFrame frame = new JFrame();
    JPanel container = new JPanel();
    container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS));
    CustomPanel customPanel1 = new CustomPanel(Color.blue);
    CustomPanel customPanel2 = new CustomPanel(Color.red);
    CustomPanel customPanel3 = new CustomPanel(Color.green);
    container.add(customPanel1);/*from  w  ww. j a  v  a2s .  c  om*/
    container.add(customPanel2);
    container.add(customPanel3);
    frame.getContentPane().add(container);
    frame.pack();
    frame.setVisible(true);
}

From source file:AreaIntersect.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    double halfWdith = getSize().width / 2;
    double halfHeight = getSize().height / 2;

    g2.setColor(Color.green);

    leaf.setFrame(halfWdith - 16, halfHeight - 29, 15.0, 15.0);
    leaf1 = new Area(leaf);
    leaf.setFrame(halfWdith - 14, halfHeight - 47, 30.0, 30.0);
    leaf2 = new Area(leaf);
    leaf1.intersect(leaf2);//from   w  ww  . j a v a 2s .  c  o m
    g2.fill(leaf1);

}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    g.setColor(Color.GREEN);
    g.fillRect(0, 0, getWidth(), getHeight());

    // uncomment the following to draw an image
    // Image img = ...;
    // g.drawImage(img, 0, 0, this);

    super.paintComponent(g);
}

From source file:Main.java

public Main() {

    setLayout(new FlowLayout());
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    table = new Hashtable<Integer, Color>();
    table.put(1, Color.RED);/*www .ja  va2 s  .  co m*/
    table.put(2, Color.BLUE);
    table.put(3, Color.GREEN);
    table.put(4, Color.GRAY);

    c = new JComboBox<String>();
    c.addItem("Item 1");
    c.addItem("Item 2");
    c.addItem("Item 3");
    c.addItem("Item 4");
    c.addItem("Item 5");
    c.addItem("Item 6");
    c.addItem("Item 7");
    c.addItem("Item 8");

    c.setRenderer(new MyListCellRenderer(table));

    add(c);
    setSize(400, 400);
    setVisible(true);
}

From source file:ColorBlocks.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    Dimension d = getSize();//from w  ww  .j a  v a2 s  .com
    g2.translate(d.width / 2, d.height / 2);

    Color[] colors = { Color.white, Color.lightGray, Color.gray, Color.darkGray, Color.black, Color.red,
            Color.pink, Color.orange, Color.yellow, Color.green, Color.magenta, Color.cyan, Color.blue };

    float size = 25;
    float x = -size * colors.length / 2;
    float y = -size * 3 / 2;

    // Show all the predefined colors.
    for (int i = 0; i < colors.length; i++) {
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(colors[i]);
        g2.fill(r);
    }

    //a linear gradient.
    y += size;
    Color c1 = Color.yellow;
    Color c2 = Color.blue;
    for (int i = 0; i < colors.length; i++) {
        float ratio = (float) i / (float) colors.length;
        int red = (int) (c2.getRed() * ratio + c1.getRed() * (1 - ratio));
        int green = (int) (c2.getGreen() * ratio + c1.getGreen() * (1 - ratio));
        int blue = (int) (c2.getBlue() * ratio + c1.getBlue() * (1 - ratio));
        Color c = new Color(red, green, blue);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Show an alpha gradient.
    y += size;
    c1 = Color.red;
    for (int i = 0; i < colors.length; i++) {
        int alpha = (int) (255 * (float) i / (float) colors.length);
        Color c = new Color(c1.getRed(), c1.getGreen(), c1.getBlue(), alpha);
        Rectangle2D r = new Rectangle2D.Float(x + size * (float) i, y, size, size);
        g2.setPaint(c);
        g2.fill(r);
    }

    // Draw a frame around the whole thing.
    y -= size * 2;
    Rectangle2D frame = new Rectangle2D.Float(x, y, size * colors.length, size * 3);
    g2.setPaint(Color.black);
    g2.draw(frame);
}

From source file:Main.java

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

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f);

    BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    gbi.setPaint(Color.red);//from w ww .  j  av a  2 s.  com
    gbi.fillRect(0, 0, 40, 40);
    gbi.setComposite(ac);

    gbi.setPaint(Color.green);
    gbi.fillRect(5, 5, 40, 40);

    g2d.drawImage(buffImg, 20, 20, null);
}

From source file:CompositingDST.java

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

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST, 0.5f);

    BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    gbi.setPaint(Color.red);// w w w.ja  va 2  s.  co  m
    gbi.fillRect(0, 0, 40, 40);
    gbi.setComposite(ac);

    gbi.setPaint(Color.green);
    gbi.fillRect(5, 5, 40, 40);

    g2d.drawImage(buffImg, 20, 20, null);
}

From source file:CompositingDST_ATOP.java

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

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC, 0.5f);

    BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    gbi.setPaint(Color.red);//from ww  w .  j  ava  2 s .c o m
    gbi.fillRect(0, 0, 40, 40);
    gbi.setComposite(ac);

    gbi.setPaint(Color.green);
    gbi.fillRect(5, 5, 40, 40);

    g2d.drawImage(buffImg, 20, 20, null);
}

From source file:CompositingDST_ATOP.java

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

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OUT, 0.5f);

    BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    gbi.setPaint(Color.red);/*from w  ww.  ja v a2 s.  c om*/
    gbi.fillRect(0, 0, 40, 40);
    gbi.setComposite(ac);

    gbi.setPaint(Color.green);
    gbi.fillRect(5, 5, 40, 40);

    g2d.drawImage(buffImg, 20, 20, null);
}

From source file:CompositingDST_ATOP.java

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

    AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_OUT, 0.5f);

    BufferedImage buffImg = new BufferedImage(60, 60, BufferedImage.TYPE_INT_ARGB);
    Graphics2D gbi = buffImg.createGraphics();

    gbi.setPaint(Color.red);//ww w.j av  a  2  s. c o  m
    gbi.fillRect(0, 0, 40, 40);
    gbi.setComposite(ac);

    gbi.setPaint(Color.green);
    gbi.fillRect(5, 5, 40, 40);

    g2d.drawImage(buffImg, 20, 20, null);
}