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:edu.clemson.cs.nestbed.client.gui.MotePanel.java

public void paintDisabledPattern(Graphics g) {
    int arcSize = 4;
    int width = getWidth() - 1;
    int height = getHeight() - 1;

    g.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcSize, arcSize);

    for (int i = 1, numLines = 3; i <= numLines; ++i) {
        g.drawLine(width / numLines * i, 0, 0, height / numLines * i);
        g.drawLine(width, height / numLines * i, width / numLines * i, height);
    }/* w ww  .j  av a2  s . c om*/
}

From source file:PrintSampleApp.java

public void paint(Graphics g) {
    Dimension size = getSize();//from   ww  w.j a  va  2s .com
    int width = size.width;
    int height = size.height;
    int x1 = (int) (width * 0.1);
    int x2 = (int) (width * 0.9);
    int y1 = (int) (height * 0.1);
    int y2 = (int) (height * 0.9);
    g.drawRect(x1, y1, x2 - x1, y2 - y1);
    g.drawOval(x1, y1, x2 - x1, y2 - y1);
    g.drawLine(x1, y1, x2, y2);
    g.drawLine(x2, y1, x1, y2);
    String text = "Print Me! ";
    text += text;
    text += text;
    g.drawString(text, x1, (int) ((y1 + y2) / 2));
    g.dispose();
}

From source file:haven.Utils.java

static void line(Graphics g, Coord c1, Coord c2) {
    g.drawLine(c1.x, c1.y, c2.x, c2.y);
}

From source file:Main.java

public void paint(Graphics g, Shape a) {
    super.paint(g, a);
    Color c = (Color) getElement().getAttributes().getAttribute("Underline-Color");
    if (c != null) {
        int y = a.getBounds().y + (int) getGlyphPainter().getAscent(this);
        int x1 = a.getBounds().x;
        int x2 = a.getBounds().width + x1;

        g.setColor(c);//from www. j a va 2s .  c  o  m
        g.drawLine(x1, y, x2, y);
    }
}

From source file:edu.mit.fss.tutorial.part4.ControlPanel.java

@Override
public void paint(Graphics g) {
    // Calls the super-class paint method for the default background.
    super.paint(g);

    // Set color to gray and draw the x-axis (Y=0) and y=axis (X=0).
    g.setColor(Color.gray);/*ww w  .ja v  a 2  s  .  c  om*/
    g.drawLine(0, getHeight() / 2, getWidth(), getHeight() / 2);
    g.drawLine(getWidth() / 2, 0, getWidth() / 2, getHeight());

    // Make sure no changes to elements can take place while painting.
    synchronized (elements) {
        // For each surface element...
        for (SurfaceElement e : elements) {
            if (e instanceof MobileElement) {
                // If it is a MobileElement, use blue color.
                g.setColor(Color.blue);
            } else {
                // Otherwise use black color.
                g.setColor(Color.black);
            }
            // Determine the screen location for the element.
            int[] location = getScreenLocation(e.getPosition());

            // Fill an oval at the location (offset by half the oval size).
            g.fillOval(location[0] - ELEMENT_SIZE / 2, location[1] - ELEMENT_SIZE / 2, ELEMENT_SIZE,
                    ELEMENT_SIZE);

            // Draw the element name to the right of the oval, offset by
            // 2 pixels to the right and half the oval size vertically.
            g.drawString(e.getName(), location[0] + ELEMENT_SIZE / 2 + 2,
                    location[1] + ELEMENT_SIZE / 2 + ELEMENT_SIZE / 2);
        }
    }
}

From source file:AlphaTest.java

/**
 * Draws a Line into the graph area for the plot.
 *//*from  w  w  w. j  av  a  2s .com*/
protected void drawGraphLine(Graphics g, double x1, double y1, double x2, double y2) {
    g.drawLine((int) (m_nGraphInsetX + x1), (int) (m_nGraphInsetY + m_nGraphMaxHeight - y1),
            (int) (m_nGraphInsetX + x2), (int) (m_nGraphInsetY + m_nGraphMaxHeight - y2));
}

From source file:uk.co.modularaudio.util.audio.gui.patternsequencer.PatternSequenceAmpGrid.java

private void paintGrid(final Graphics g, final int startCol, final int endCol) {
    g.setColor(foregroundColour);/* ww  w .j  a v a  2 s. com*/
    for (int i = startCol; i <= endCol; i++) {
        final int lineStartY = AMP_BOX_DELTA;
        final int lineX = i * cellDimensions.width;
        final int lineEndY = size.height - 1;
        g.drawLine(lineX, lineStartY, lineX, lineEndY);
    }
    g.drawLine(minPointToPaint.x, AMP_BOX_DELTA, maxPointToPaint.x, AMP_BOX_DELTA);
    g.drawLine(minPointToPaint.x, size.height - 1, maxPointToPaint.x, size.height - 1);
}

From source file:width.java

/**
     * Paint it./*from w  ww  .java 2s  . c  o m*/
     */
    public void paint(Graphics g) {
        Dimension d = getSize();
        g.setColor(Color.black);
        int xoff = d.width / 3;
        int yoff = d.height / 3;
        g.drawLine(xoff, 0, xoff, d.height);
        g.drawLine(2 * xoff, 0, 2 * xoff, d.height);
        g.drawLine(0, yoff, d.width, yoff);
        g.drawLine(0, 2 * yoff, d.width, 2 * yoff);

        int i = 0;
        for (int r = 0; r < 3; r++) {
            for (int c = 0; c < 3; c++, i++) {
                if ((white & (1 << i)) != 0) {
                    g.drawImage(notImage, c * xoff + 1, r * yoff + 1, this);
                } else if ((black & (1 << i)) != 0) {
                    g.drawImage(crossImage, c * xoff + 1, r * yoff + 1, this);
                }
            }
        }
    }

From source file:uk.co.modularaudio.util.swing.colouredtoggle.ColouredTextToggle.java

@Override
public void paint(final Graphics g) {
    super.paint(g);
    g.setColor(backgroundColour);// ww  w.  j  av a 2 s  .co m

    final int yOffset = Math.round((getHeight() / 2.0f) - (CLICKABLE_BOX_WIDTH / 2.0f));

    g.fillRect(4, 4 + yOffset, CLICKABLE_BOX_WIDTH - 8, CLICKABLE_BOX_WIDTH - 8);

    if (active) {
        // Draw an X inside the box
        g.setColor(surroundColour);
        g.drawLine(5, 5 + yOffset, CLICKABLE_BOX_WIDTH - 6, CLICKABLE_BOX_WIDTH - 6 + yOffset);
        g.drawLine(CLICKABLE_BOX_WIDTH - 6, 5 + yOffset, 5, CLICKABLE_BOX_WIDTH - 6 + yOffset);
    }
}

From source file:nl.b3p.kaartenbalie.core.server.b3pLayering.ConfigLayer.java

protected void drawEdgedBox(Graphics g2d, int x, int y, int w, int h) {
    g2d.setColor(KBConfiguration.OHD_borderBoxBackground);
    g2d.fillRect(x, y, w, h);/*from w w w  .  j  av  a2 s  .c  om*/
    g2d.setColor(KBConfiguration.OHD_borderBoxTopLeft);
    g2d.drawLine(x, y, x + w, y); //Top
    g2d.drawLine(x, y + h, x, y); //Left
    g2d.setColor(KBConfiguration.OHD_borderBoxBottomRight);
    g2d.drawLine(x + w, y + h, x, y + h); //Bottom
    g2d.drawLine(x + w, y, x + w, y + h); //Right

}