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

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

    BasicStroke bs = new BasicStroke(16.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    g2.setStroke(bs);// w  w  w  .  j  a v a  2 s  . c  o  m
    g.drawLine(30, 20, 270, 20);
}

From source file:OvalBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    width--;//from www.j  av  a 2 s  .c  o  m
    height--;

    g.setColor(lightColor);
    g.drawLine(x, y + height - ovalHeight, x, y + ovalHeight);
    g.drawArc(x, y, 2 * ovalWidth, 2 * ovalHeight, 180, -90);
    g.drawLine(x + ovalWidth, y, x + width - ovalWidth, y);
    g.drawArc(x + width - 2 * ovalWidth, y, 2 * ovalWidth, 2 * ovalHeight, 90, -90);

    g.setColor(darkColor);
    g.drawLine(x + width, y + ovalHeight, x + width, y + height - ovalHeight);
    g.drawArc(x + width - 2 * ovalWidth, y + height - 2 * ovalHeight, 2 * ovalWidth, 2 * ovalHeight, 0, -90);
    g.drawLine(x + ovalWidth, y + height, x + width - ovalWidth, y + height);
    g.drawArc(x, y + height - 2 * ovalHeight, 2 * ovalWidth, 2 * ovalHeight, -90, -90);
}

From source file:MainClass.java

public void paint(Graphics g) {
    if (p != null) {
        Dimension d = getSize();/*from  w  w w .j a va2 s. com*/
        int xc = d.width / 2;
        int yc = d.height / 2;
        g.drawLine(xc, yc, p.x, p.y);
    }
}

From source file:Main.java

public void actionPerformed(ActionEvent evt) {
    Graphics g = getGraphics();
    Point p = getClick();// www .j a  v a  2s .  com
    g.drawOval(p.x - 2, p.y - 2, 4, 4);
    Point q = getClick();
    g.drawOval(q.x - 2, q.y - 2, 4, 4);
    g.drawLine(p.x, p.y, q.x, q.y);
    g.dispose();
}

From source file:Wavelet.java

/**
 * Called by AWT when the window needs painting; just recompute all the data
 * and draw it, since it's a simple calculation and simpler than
 * precomputing and storing the data.//from w w w.  j av a 2 s .  com
 */
public void paint(Graphics g) {
    Dimension d = getSize();
    for (int x = 0; x < d.width; x++) {
        g.drawLine(x, 20 + (int) func(x), x + 1, 20 + (int) func(x + 1));
    }
}

From source file:org.stanwood.nwn2.gui.view.UIIconView.java

private void drawMissingIcon(int x, int y, int width, int height, Graphics g) {
    g.setColor(Color.RED);/* w  ww . j  a  v  a 2 s . c  o  m*/

    g.drawRect(x, y, width, height);

    g.drawLine(x, y, x + width, y + height);
    g.drawLine(x + width, y, x, y + height);
}

From source file:ColorVariousObjects.java

public void paint(Graphics g) {
    Color c1 = new Color(255, 100, 100);
    Color c2 = new Color(100, 255, 100);
    Color c3 = new Color(100, 100, 255);

    g.setColor(c1);//from w  w w.  j  a v  a 2 s . c o  m
    g.drawLine(0, 0, 100, 100);
    g.drawLine(0, 100, 100, 0);

    g.setColor(c2);
    g.drawLine(40, 25, 250, 180);
    g.drawLine(75, 90, 400, 400);

    g.setColor(c3);
    g.drawLine(20, 150, 400, 40);
    g.drawLine(5, 290, 80, 19);

    g.setColor(Color.red);
    g.drawOval(10, 10, 50, 50);
    g.fillOval(70, 90, 140, 100);

    g.setColor(Color.blue);
    g.drawOval(190, 10, 90, 30);
    g.drawRect(10, 10, 60, 50);

    g.setColor(Color.cyan);
    g.fillRect(100, 10, 60, 50);
    g.drawRoundRect(190, 10, 60, 50, 15, 15);
}

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

private void lineTo(final Point p) {
    if (current != null) {
        log.debug("draw line");
        final Graphics g = getGraphics();
        g.drawLine(current.x, current.y, p.x, p.y);
        g.dispose();/*from   ww  w .  j a v  a 2  s  . c  om*/
    }
    curve.add(current = p);
}

From source file:GridsCanvas.java

public void paint(Graphics g) {
    int i;//from   w  w  w .jav  a  2 s  .com
    width = getSize().width;
    height = getSize().height;

    // draw the rows
    int rowHt = height / (rows);
    for (i = 0; i < rows; i++)
        g.drawLine(0, i * rowHt, width, i * rowHt);

    // draw the columns
    int rowWid = width / (cols);
    for (i = 0; i < cols; i++)
        g.drawLine(i * rowWid, 0, i * rowWid, height);
}

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

protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.drawLine(100, 110, 100, 90);
    g.drawLine(110, 100, 90, 100);//  ww  w  .  jav  a  2 s.com
    circle(g, 100, 100, 10, 10);
    g.drawArc(100, 100, 20, 20, 0, 360);
    g.drawArc(100, 100, -20, -20, 0, 360);
}