Example usage for java.awt.geom GeneralPath lineTo

List of usage examples for java.awt.geom GeneralPath lineTo

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath lineTo.

Prototype

public abstract void lineTo(double x, double y);

Source Link

Document

Adds a point to the path by drawing a straight line from the current coordinates to the new specified coordinates specified in double precision.

Usage

From source file:Main.java

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

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);//  ww  w . j a v  a  2 s.  c om

    BasicStroke bs = new BasicStroke(36.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
    g2.setStroke(bs);

    GeneralPath path = new GeneralPath();
    path.moveTo(30.0f, 90.0f);
    path.lineTo(150.0f, 20.0f);
    path.lineTo(270.0f, 90.0f);
    g2.draw(path);
}

From source file:MainClass.java

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

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);/*  w  w w  .  ja  va  2  s . c  om*/

    BasicStroke bs = new BasicStroke(36.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    g2.setStroke(bs);

    GeneralPath path = new GeneralPath();
    path.moveTo(30.0f, 90.0f);
    path.lineTo(150.0f, 20.0f);
    path.lineTo(270.0f, 90.0f);
    g2.draw(path);

}

From source file:MainClass.java

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

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);// w w w  .j a v a  2s  . c  om

    BasicStroke bs = new BasicStroke(36.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL);
    g2.setStroke(bs);

    GeneralPath path = new GeneralPath();
    path.moveTo(30.0f, 90.0f);
    path.lineTo(150.0f, 20.0f);
    path.lineTo(270.0f, 90.0f);
    g2.draw(path);

}

From source file:MainClass.java

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

    RenderingHints rh = g2.getRenderingHints();
    rh.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHints(rh);/*from w w  w .j a  v  a 2s.c  om*/

    BasicStroke bs = new BasicStroke(36.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND);
    g2.setStroke(bs);

    GeneralPath path = new GeneralPath();
    path.moveTo(30.0f, 90.0f);
    path.lineTo(150.0f, 20.0f);
    path.lineTo(270.0f, 90.0f);
    g2.draw(path);

}

From source file:MyCanvas.java

public void paint(Graphics g) {
    Graphics2D g2D = (Graphics2D) g;
    Point2D.Float point = new Point2D.Float(100, 100); // store start point
    GeneralPath p = new GeneralPath(GeneralPath.WIND_NON_ZERO);
    p.moveTo(point.x, point.y);/*from   w  w w  . j  ava 2  s  . c o  m*/
    p.lineTo(point.x + 20.0f, point.y - 5.0f); // Line from start to A
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x + 5.0f, point.y - 20.0f); // Line from A to B
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x + 5.0f, point.y + 20.0f); // Line from B to C
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x + 20.0f, point.y + 5.0f); // Line from C to D
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x - 20.0f, point.y + 5.0f); // Line from D to E
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x - 5.0f, point.y + 20.0f); // Line from E to F
    point = (Point2D.Float) p.getCurrentPoint();
    p.lineTo(point.x - 5.0f, point.y - 20.0f); // Line from F to g
    p.closePath(); // Line from G to start
    g2D.draw(p);
}

From source file:AttributesApp.java

public AttributesApp() {
    setBackground(Color.lightGray);
    setSize(500, 200);//from  w ww. j  ava2s. co  m

    attribString = new AttributedString(text);

    GeneralPath star = new GeneralPath();
    star.moveTo(0, 0);
    star.lineTo(10, 30);
    star.lineTo(-10, 10);
    star.lineTo(10, 10);
    star.lineTo(-10, 30);
    star.closePath();
    GraphicAttribute starShapeAttr = new ShapeGraphicAttribute(star, GraphicAttribute.TOP_ALIGNMENT, false);
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, starShapeAttr, 0, 1);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(255, 255, 0), 0, 1);

    int index = text.indexOf("Java Source");
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index, index + 7);
    Font font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 7);

    loadImage();
    BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this),
            BufferedImage.TYPE_INT_ARGB);
    Graphics2D big = bimage.createGraphics();
    big.drawImage(image, null, this);
    GraphicAttribute javaImageAttr = new ImageGraphicAttribute(bimage, GraphicAttribute.TOP_ALIGNMENT, 0, 0);

    index = text.indexOf("Java");
    attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, javaImageAttr, index - 1, index);

    font = new Font("serif", Font.BOLD, 60);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 4);
    attribString.addAttribute(TextAttribute.FOREGROUND, new Color(243, 63, 163), index, index + 4); // Start and end indexes.

    index = text.indexOf("source");
    attribString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, index, index + 2);

    index = text.indexOf("and support");
    font = new Font("sanserif", Font.ITALIC, 40);
    attribString.addAttribute(TextAttribute.FONT, font, index, index + 10);

    attribString.addAttribute(TextAttribute.FOREGROUND, Color.white, index, index + 2); // Start and end indexes.
    attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index + 3, index + 10); // Start and end indexes.
}

From source file:TransformersRotationTranslation.java

protected Shape createAxes() {
    GeneralPath path = new GeneralPath();

    // Axes.//w  ww  .j a v a  2  s .  co  m
    path.moveTo(-length, 0);
    path.lineTo(length, 0);
    path.moveTo(0, -length);
    path.lineTo(0, length);
    // Arrows.
    path.moveTo(length - arrowLength, -arrowLength);
    path.lineTo(length, 0);
    path.lineTo(length - arrowLength, arrowLength);
    path.moveTo(-arrowLength, length - arrowLength);
    path.lineTo(0, length);
    path.lineTo(arrowLength, length - arrowLength);
    // Half-centimeter tick marks
    float cm = 72 / 2.54f;
    float lengthCentimeter = length / cm;
    for (float i = 0.5f; i < lengthCentimeter; i += 1.0f) {
        float tick = i * cm;
        path.moveTo(tick, -tickSize / 2);
        path.lineTo(tick, tickSize / 2);
        path.moveTo(-tick, -tickSize / 2);
        path.lineTo(-tick, tickSize / 2);
        path.moveTo(-tickSize / 2, tick);
        path.lineTo(tickSize / 2, tick);
        path.moveTo(-tickSize / 2, -tick);
        path.lineTo(tickSize / 2, -tick);
    }
    // Full-centimeter tick marks
    for (float i = 1.0f; i < lengthCentimeter; i += 1.0f) {
        float tick = i * cm;
        path.moveTo(tick, -tickSize);
        path.lineTo(tick, tickSize);
        path.moveTo(-tick, -tickSize);
        path.lineTo(-tick, tickSize);
        path.moveTo(-tickSize, tick);
        path.lineTo(tickSize, tick);
        path.moveTo(-tickSize, -tick);
        path.lineTo(tickSize, -tick);
    }
    return path;
}

From source file:LineStyles.java

/** This method draws the example figure */
public void paint(Graphics g1) {
    Graphics2D g = (Graphics2D) g1;
    // Use anti-aliasing to avoid "jaggies" in the lines
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    // Define the shape to draw
    GeneralPath shape = new GeneralPath();
    shape.moveTo(xpoints[0], ypoints[0]); // start at point 0
    shape.lineTo(xpoints[1], ypoints[1]); // draw a line to point 1
    shape.lineTo(xpoints[2], ypoints[2]); // and then on to point 2

    // Move the origin to the right and down, creating a margin
    g.translate(20, 40);/*from w w w . j av  a 2s  .c  o  m*/

    // Now loop, drawing our shape with the three different line styles
    for (int i = 0; i < linestyles.length; i++) {
        g.setColor(Color.gray); // Draw a gray line
        g.setStroke(linestyles[i]); // Select the line style to use
        g.draw(shape); // Draw the shape

        g.setColor(Color.black); // Now use black
        g.setStroke(thindashed); // And the thin dashed line
        g.draw(shape); // And draw the shape again.

        // Highlight the location of the vertexes of the shape
        // This accentuates the cap and join styles we're demonstrating
        for (int j = 0; j < xpoints.length; j++)
            g.fillRect(xpoints[j] - 2, ypoints[j] - 2, 5, 5);

        g.drawString(capNames[i], 5, 105); // Label the cap style
        g.drawString(joinNames[i], 5, 120); // Label the join style

        g.translate(150, 0); // Move over to the right before looping again
    }
}

From source file:GeneralPathDemo2D.java

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

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

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

    g2.draw(polygon);
    g2.drawString("GeneralPath", x, 250);

}

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);//  w w  w .  j  a v  a 2  s.c o  m
    int x = 5;
    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);
}