Example usage for java.awt Graphics drawLine

List of usage examples for java.awt Graphics drawLine

Introduction

In this page you can find the example usage for java.awt Graphics drawLine.

Prototype

public abstract void drawLine(int x1, int y1, int x2, int y2);

Source Link

Document

Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this graphics context's coordinate system.

Usage

From source file:PaintUtils.java

private static void drawColors(Color[] colors, Graphics g, int x1, int y1, int x2, int y2, int direction) {
    for (int a = 0; a < colors.length; a++) {
        g.setColor(colors[colors.length - a - 1]);
        if (direction == SwingConstants.SOUTH) {
            g.drawLine(x1, y1 - a, x2, y2 - a);
        } else if (direction == SwingConstants.NORTH) {
            g.drawLine(x1, y1 + a, x2, y2 + a);
        } else if (direction == SwingConstants.EAST) {
            g.drawLine(x1 - a, y1, x2 - a, y2);
        } else if (direction == SwingConstants.WEST) {
            g.drawLine(x1 + a, y1, x2 + a, y2);
        }// w  w w .j a  v a  2s. c o m
    }
}

From source file:com.baidu.rigel.biplatform.ma.auth.resource.RandomValidateCode.java

private static void drowLine(Graphics g) {
    int x = random.nextInt(width);
    int y = random.nextInt(height);
    int xl = random.nextInt(13);
    int yl = random.nextInt(15);
    g.drawLine(x, y, x + xl, y + yl);
}

From source file:YAxisDiffAlign.java

private static Container makeIt(String title, boolean more) {
    JPanel container = new JPanel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Insets insets = getInsets();
            int width = getWidth() - insets.left - insets.right;
            int halfWidth = width / 2 + insets.left;
            int height = getHeight();
            int halfHeight = height / 2 + insets.top;
            g.drawLine(halfWidth, 0, halfWidth, height);
        }//from  w w  w .  ja  v a 2 s. co  m
    };
    container.setBorder(BorderFactory.createTitledBorder(title));
    BoxLayout layout = new BoxLayout(container, BoxLayout.Y_AXIS);
    container.setLayout(layout);

    JButton button;
    button = new JButton("0.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.LEFT_ALIGNMENT);
    container.add(button);
    if (more) {
        button = new JButton(".25");
        button.setOpaque(false);
        button.setAlignmentX(0.25f);
        container.add(button);
        button = new JButton(".5");
        button.setOpaque(false);
        button.setAlignmentX(Component.CENTER_ALIGNMENT);
        container.add(button);
        button = new JButton(".75");
        button.setOpaque(false);
        button.setAlignmentX(0.75f);
        container.add(button);
    }
    button = new JButton("1.0");
    button.setOpaque(false);
    button.setAlignmentX(Component.RIGHT_ALIGNMENT);
    container.add(button);

    return container;
}

From source file:org.jcurl.mr.exp.gui.MouseSketchPanel.java

/**
 * Paint the given curve./*  w ww  . ja va 2 s  .c o m*/
 * 
 * @param g
 * @param c
 */
private static void paint(final Graphics g, final PointList c) {
    final Iterator it = c.points();
    if (!it.hasNext())
        return;
    Point p = (Point) it.next();
    while (it.hasNext()) {
        final Point p2 = (Point) it.next();
        g.drawLine(p.x, p.y, p2.x, p2.y);
        p = p2;
    }
}

From source file:ala.soils2sat.DrawingUtils.java

public static void drawRoundedRect(Graphics g, int left, int top, int right, int bottom) {
    Graphics2D g2d = (Graphics2D) g;
    g.drawLine(left + cornerSize, top, right - cornerSize, top);
    g.drawLine(left + cornerSize, bottom, right - cornerSize, bottom);
    g.drawLine(left, top + cornerSize, left, bottom - cornerSize);
    g.drawLine(right, top + cornerSize, right, bottom - cornerSize);
    final Object previousAntiAliasingHint = g2d.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
    final Stroke previousStroke = g2d.getStroke();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    try {//from w  w  w .  j a  va 2s.  c  om
        g.drawLine(left, top + cornerSize, left + cornerSize, top);
        g.drawLine(left, bottom - cornerSize, left + cornerSize, bottom);
        g.drawLine(right, top + cornerSize, right - cornerSize, top);
        g.drawLine(right, bottom - cornerSize, right - cornerSize, bottom);
    } finally {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, previousAntiAliasingHint);
        g2d.setStroke(previousStroke);
    }
}

From source file:GraphicsUtil.java

static public void drawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle) {
    double offs = headAngle * Math.PI / 180.0;
    double angle = Math.atan2(y0 - y1, x0 - x1);
    int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
            x1 + (int) (headLength * Math.cos(angle - offs)) };
    int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
            y1 + (int) (headLength * Math.sin(angle - offs)) };
    g.drawLine(x0, y0, x1, y1);
    g.drawPolyline(xs, ys, 3);//  w  ww  .j  a  v  a 2 s. c  o  m
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private static void drawArrowHead(Graphics graphics, int x, int y, double theta, double length) {
    final double b = (theta + 1) * Constants.DTOR;
    final int x3 = (int) (length * FastMath.cos(b));
    final int y3 = (int) (length * FastMath.sin(b));
    graphics.drawLine(x, y, x3, y3);

    final double c = (theta - 1) * Constants.DTOR;
    final int x4 = (int) (length * FastMath.cos(c));
    final int y4 = (int) (length * FastMath.sin(c));
    graphics.drawLine(x, y, x4, y4);/*from   w w  w .j  av a 2 s .  c  o  m*/
}

From source file:org.esa.nest.dat.views.polarview.PolarCanvas.java

private static void drawWindDirection(Graphics graphics, double radius, double theta) {
    final double a = theta * Constants.DTOR;
    final int x1 = (int) (radius * FastMath.cos(a));
    final int y1 = (int) (radius * FastMath.sin(a));
    final int x2 = (int) ((radius + 50) * FastMath.cos(a));
    final int y2 = (int) ((radius + 50) * FastMath.sin(a));

    graphics.setColor(Color.black);
    graphics.drawLine(x1, y1, x2, y2);

    drawArrowHead(graphics, x2, y2, theta, radius + 40);
}

From source file:GUITasks.java

public static void drawDashed(Graphics g, int x1, int y1, int x2, int y2, int dashSize, int gapSize) {
    if (x2 < x1) {
        int temp = x1;
        x1 = x2;//  ww w  . j  av a  2  s.co  m
        x2 = temp;
    }
    if (y2 < y1) {
        int temp = y1;
        y1 = y2;
        y2 = temp;
    }
    int totalDash = dashSize + gapSize;
    if (y1 == y2) {
        int virtualStartX = (x1 / totalDash) * totalDash;
        for (int x = virtualStartX; x < x2; x += totalDash) {
            int topX = x + dashSize;
            if (topX > x2) {
                topX = x2;
            }
            int firstX = x;
            if (firstX < x1) {
                firstX = x1;
            }
            if (firstX < topX) {
                g.drawLine(firstX, y1, topX, y1);
            }
        }
    } else if (x1 == x2) {
        int virtualStartY = (y1 / totalDash) * totalDash;
        for (int y = virtualStartY; y < y2; y += totalDash) {
            int topY = y + dashSize;
            if (topY > y2) {
                topY = y2;
            }
            int firstY = y;
            if (firstY < y1) {
                firstY = y1;
            }
            if (firstY < topY) {
                g.drawLine(x1, firstY, x1, topY);
            }
        }
    } else {
        // Not supported
        g.drawLine(x1, y1, x2, y2);
    }
}

From source file:MainClass.java

public void paint(Graphics g) {
    g.drawLine(10, 15, 100, 115);
}