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

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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape s = new Ellipse2D.Float(20, 50, 250, 150);
    g2.setPaint(Color.BLACK);
    g2.draw(s);/* www.ja va  2s.c  o m*/
}

From source file:DashedStrokeDemo.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    float dash[] = { 10.0f };
    g2.setStroke(new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dash, 0.0f));

    g2.setPaint(Color.blue);

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

    g2.draw(r);/*ww  w  . j  a  v a2  s  .c  o m*/
}

From source file:maltcms.ui.fileHandles.serialized.SeriesPaintComboBoxRenderer.java

private BufferedImage createColorImage(Paint p) {
    BufferedImage bi = new BufferedImage(10, 10, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = bi.createGraphics();
    g2.setPaint(p);
    g2.fillRect(0, 0, bi.getWidth(), bi.getHeight());
    return bi;/*from ww  w. j  ava 2  s. com*/
}

From source file:Main.java

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

    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);/*from  ww  w  .j ava2 s  . c o  m*/
    g2.setStroke(stroke);

    g2.setPaint(Color.black);
    g2.draw(new Rectangle2D.Float(10, 20, 30, 40));
}

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, new float[] { 3, 1 },
            0);//from   w  ww .j  a  va  2s .c  o  m
    g2.setStroke(stroke);

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

From source file:com.bdb.weather.display.current.WindDirPointer.java

/**
 * Draws the pointer./* w ww  .  ja  v a  2s.c o m*/
 * 
 * @param g2 The graphics target.
 * @param plot The plot.
 * @param frame The dial's reference frame.
 * @param view The dial's view.
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {
    g2.setPaint(Color.blue);
    g2.setStroke(new BasicStroke(1.0f));
    DialScale scale = plot.getScaleForDataset(getDatasetIndex());
    double value = plot.getValue(getDatasetIndex());
    double angle = scale.valueToAngle(value % 360.0);

    Rectangle2D outerRect = DialPlot.rectangleByRadius(frame, outerRadius, outerRadius);
    Rectangle2D innerRect = DialPlot.rectangleByRadius(frame, outerRadius - innerOffset,
            outerRadius - innerOffset);

    g2.setPaint(getOutlinePaint());
    Arc2D arc1 = new Arc2D.Double(outerRect, angle - (ARC_LENGTH / 2), ARC_LENGTH, Arc2D.OPEN);
    g2.draw(arc1);
    Arc2D arc2 = new Arc2D.Double(innerRect, angle, 0.0, Arc2D.OPEN);
    GeneralPath gp = new GeneralPath();
    gp.moveTo(arc1.getStartPoint().getX(), arc1.getStartPoint().getY());
    gp.lineTo(arc2.getStartPoint().getX(), arc2.getStartPoint().getY());
    gp.lineTo(arc1.getEndPoint().getX(), arc1.getEndPoint().getY());
    g2.draw(gp);
    if (fill) {
        g2.setPaint(getFillPaint());
        g2.fill(gp);
    }
}

From source file:eu.hydrologis.jgrass.charting.impl.LineDrawer.java

/**
 * Draws the circle./*from  w w w .  j  ava  2s . c o  m*/
 * 
 * @param g2 the graphics device.
 * @param area the area in which to draw.
 */
public void draw(Graphics2D g2, Rectangle2D area) {
    if (this.outlinePaint != null && this.outlineStroke != null) {
        g2.setPaint(this.outlinePaint);
        g2.setStroke(this.outlineStroke);
    } else {
        g2.setPaint(Color.black);
        g2.setStroke(new BasicStroke(1.0f));
    }

    Line2D line = new Line2D.Double(area.getCenterX(), area.getMinY(), area.getCenterX(), area.getMaxY());
    g2.draw(line);
}

From source file:MainClass.java

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

    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 },
            0);//from  w ww  .  ja  v a2 s  .  c o m
    g2.setStroke(stroke);

    g2.setPaint(Color.black);
    g2.draw(shape);

}

From source file:MainClass.java

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

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Rectangle2D r = new Rectangle2D.Double(50, 50, 150, 100);
    g2.setPaint(Color.red);
    g2.fill(r);//  w  w  w  .j  ava2  s .c  o  m

    Composite c = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .4f);
    g2.setComposite(c);

    g2.setPaint(Color.blue);
    g2.setFont(new Font("Times New Roman", Font.PLAIN, 72));
    g2.drawString("www.java2s.com", 25, 130);
}

From source file:TexturedText.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setPaint(tp);
    g2.setFont(myFont);/*  w  ww  .jav  a  2s  .c om*/
    g2.drawString(mesg, 20, 100);
}