Example usage for java.awt Graphics2D setPaint

List of usage examples for java.awt Graphics2D setPaint

Introduction

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

Prototype

public abstract void setPaint(Paint paint);

Source Link

Document

Sets the Paint attribute for the Graphics2D context.

Usage

From source file:ArcDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;//  w  w w .  j a  v a 2s  . co  m
    int y = 7;

    g2.setStroke(wideStroke);
    g2.draw(new Arc2D.Double(x, y, 200, 200, 90, 135, Arc2D.OPEN));
    g2.drawString("Arc2D", x, 250);
}

From source file:Main.java

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

    Stroke stroke = new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.1F);
    g2.setStroke(stroke);/*w  w w . j  a  v a 2s . c om*/

    g2.setPaint(Color.black);
    g2.draw(new Rectangle2D.Float(10, 10, 200, 200));
}

From source file:FilledRectangleDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/*from   w  w w  .ja v  a 2  s. c om*/
    int y = 7;

    g2.setPaint(Color.red);
    g2.fill(new Rectangle2D.Double(x, y, 200, 200));
    g2.setPaint(Color.black);
    g2.drawString("Filled Rectangle2D", x, 250);
}

From source file:EllipseDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/*ww w  .  jav a  2s .  c  o  m*/
    int y = 7;

    g2.setStroke(stroke);
    g2.draw(new Ellipse2D.Double(x, y, 200, 200));
    g2.drawString("Ellipse2D", x, 250);

}

From source file:RectangleDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/* w  w w  .  j a  v a 2s.  co m*/
    int y = 7;

    g2.setStroke(stroke);
    g2.draw(new Rectangle2D.Double(x, y, 200, 200));
    g2.drawString("Rectangle2D", x, 250);

}

From source file:DashedRectangleDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;//from  w  ww  . jav a 2s. c  om
    int y = 7;

    g2.setStroke(dashed);
    g2.draw(new RoundRectangle2D.Double(x, y, 200, 200, 10, 10));
    g2.drawString("RoundRectangle2D", x, 250);

}

From source file:GradientPaintDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/*from   www.  j  ava  2 s .c  om*/
    int y = 7;
    // fill RoundRectangle2D.Double
    GradientPaint redtowhite = new GradientPaint(x, y, Color.red, 200, y, Color.blue);
    g2.setPaint(redtowhite);
    g2.fill(new RoundRectangle2D.Double(x, y, 200, 200, 10, 10));
    g2.setPaint(Color.black);
    g2.drawString("Filled RoundRectangle2D", x, 250);

}

From source file:Main.java

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

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.isCyclic());
    g2d.setPaint(gp1);
    g2d.fillRect(20, 20, 300, 40);//from  w  w  w . j  a  va2 s. com

}

From source file:Main.java

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

    GradientPaint gp1 = new GradientPaint(5, 5, Color.red, 20, 20, Color.yellow, true);

    System.out.println(gp1.getColor2());
    g2d.setPaint(gp1);
    g2d.fillRect(20, 20, 300, 40);//w w w  .  j ava 2s  .co  m

}

From source file:GeneralPathOpenDemo2D.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    g2.setPaint(Color.gray);
    int x = 5;/*w  w  w  .  ja  v  a  2s .c  om*/
    int y = 7;

    // draw GeneralPath (polyline)

    int xPoints[] = { x, 200, x, 200 };
    int yPoints[] = { y, 200, 200, y };
    GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length);
    polyline.moveTo(xPoints[0], yPoints[0]);
    for (int index = 1; index < xPoints.length; index++) {
        polyline.lineTo(xPoints[index], yPoints[index]);
    }

    g2.draw(polyline);
    g2.drawString("GeneralPath (open)", x, 250);
}