Example usage for java.awt Graphics2D setColor

List of usage examples for java.awt Graphics2D setColor

Introduction

In this page you can find the example usage for java.awt Graphics2D setColor.

Prototype

public abstract void setColor(Color c);

Source Link

Document

Sets this graphics context's current color to the specified color.

Usage

From source file:Translation.java

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

    g2d.setColor(new Color(150, 150, 150));
    g2d.fillRect(20, 20, 80, 50);//from   ww w  .  j  a v  a 2 s.co  m
    g2d.translate(150, 50);
    g2d.fillRect(20, 20, 80, 50);
}

From source file:Rectangles.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(new Color(212, 212, 212));
    g2d.drawRect(10, 15, 90, 60);/*from w ww .  java  2s . co m*/

    g2d.setColor(new Color(31, 21, 1));
    g2d.fillRect(250, 195, 90, 60);

}

From source file:BasicDraw.java

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

    g2d.setColor(Color.red);

    g2d.fill(new Rectangle(20, 20, 200, 200));
    int red = 230;
    int green = 45;
    int blue = 67;
    g2d.setColor(new Color(red, green, blue));
    g2d.fill(new Rectangle(40, 40, 200, 200));
}

From source file:Points.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(Color.red);

    for (int i = 0; i <= 100000; i++) {
        Dimension size = getSize();
        int w = size.width;
        int h = size.height;

        Random r = new Random();
        int x = Math.abs(r.nextInt()) % w;
        int y = Math.abs(r.nextInt()) % h;
        g2d.drawLine(x, y, x, y);//from w w w .  j  av  a 2s  . c o m
    }
}

From source file:juicebox.tools.utils.juicer.apa.APAPlotter.java

/**
 * @param g2 graphics2D object//from ww w. j a  v a  2  s.c  o m
 */
private static void plotColorScaleBar(Graphics2D g2) {
    // calculate color scale bar dimensions & location
    Point csBarTL = new Point(heatmapWidth + colorScaleHorizontalMargin, colorScaleVerticalMargin);
    Point csBarBL = new Point(heatmapWidth + colorScaleHorizontalMargin, fullHeight - colorScaleVerticalMargin);
    Rectangle csBar = new Rectangle(csBarTL.x, csBarTL.y, colorScaleWidth - 2 * colorScaleHorizontalMargin,
            fullHeight - 2 * colorScaleVerticalMargin);

    // plot the color scale linear gradient
    LinearGradientPaint gradient = new LinearGradientPaint(csBarTL, csBarBL, gradientFractions, gradientColors);
    g2.setPaint(gradient);
    g2.fill(csBar);

    // plot a border around color scale
    g2.setColor(Color.black);
    g2.drawRect(csBar.x, csBar.y, csBar.width, csBar.height);
}

From source file:Scale.java

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

    g2d.setColor(new Color(150, 150, 150));
    g2d.fillRect(0, 0, 80, 50);/*from  w  ww .  ja  v a2s .  c  om*/

    AffineTransform tx1 = new AffineTransform();
    tx1.translate(110, 20);
    tx1.scale(0.5, 0.5);

    g2d.setTransform(tx1);
    g2d.fillRect(0, 0, 80, 50);

    AffineTransform tx2 = new AffineTransform();
    tx2.translate(200, 20);
    tx2.scale(1.5, 1.5);

    g2d.setTransform(tx2);
    g2d.fillRect(0, 0, 80, 50);

}

From source file:Main.java

public MyPanel() {
    this.setLayout(new GridLayout());
    this.setPreferredSize(new Dimension(W, H));
    int w = W / 2;
    int h = H / 2;
    int r = w / 5;
    BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = bi.createGraphics();
    g.setColor(Color.gray);
    g.fillRect(0, 0, w, h);//from ww w  .j  a  v a 2  s  .co  m
    g.setColor(Color.blue);
    g.fillRect(w / 2 - r, h / 2 - r / 2, 2 * r, r);
    g.dispose();
    this.add(new JLabel(new ImageIcon(bi), JLabel.CENTER));
}

From source file:Main.java

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setColor(Color.RED);
    g2d.drawLine(0, 0, getWidth(), getHeight());
    g2d.drawLine(getWidth(), 0, 0, getHeight());
    g2d.dispose();/*from w w w.  j  a  v a 2  s . co  m*/
}

From source file:TexturePaintDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB);
    Graphics2D big = bi.createGraphics();
    big.setColor(Color.blue);
    big.fillRect(0, 0, 5, 5);/*  ww  w. ja va  2s.  c  o m*/
    big.setColor(Color.lightGray);
    big.fillOval(0, 0, 5, 5);
    Rectangle r = new Rectangle(0, 0, 5, 5);
    g2.setPaint(new TexturePaint(bi, r));

    Rectangle rect = new Rectangle(5, 5, 200, 200);

    g2.fill(rect);
}

From source file:ColorFadingAnimation.java

public void paint(Graphics g) {
    super.paint(g);
    Graphics2D g2d = (Graphics2D) g;
    g2d.setColor(new Color(50, 50, 50));
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    rh.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2d.setRenderingHints(rh);/* w ww. jav a  2s . co m*/
    g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha_rectangle));
    g2d.fill(rect);
}