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:org.jcurl.mr.gui.MouseSketchPanel.java

@Override
protected void paintComponent(final Graphics g) {
    super.paintComponent(g);
    g.drawLine(100, 110, 100, 90);
    g.drawLine(110, 100, 90, 100);/*from  www  . j  a  v a2  s  .c  om*/
    circle(g, 100, 100, 10, 10);
    g.drawArc(100, 100, 20, 20, 0, 360);
    g.drawArc(100, 100, -20, -20, 0, 360);
}

From source file:JToolbarSeparator.java

protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    Dimension size = getSize();/* ww w. j  a  v a  2s.c  om*/
    int pos = size.width / 2;
    g.setColor(Color.gray);
    g.drawLine(pos, 3, pos, size.height - 5);
    g.drawLine(pos, 2, pos + 1, 2);
    g.setColor(Color.white);
    g.drawLine(pos + 1, 3, pos + 1, size.height - 5);
    g.drawLine(pos, size.height - 4, pos + 1, size.height - 4);
}

From source file:URLLabel.java

public void paint(Graphics g) {
    super.paint(g);

    if (entered || !mousehover) {
        Rectangle r = g.getClipBounds();

        g.drawLine(0, r.height - this.getFontMetrics(this.getFont()).getDescent(),
                this.getFontMetrics(this.getFont()).stringWidth(this.getText()),
                r.height - this.getFontMetrics(this.getFont()).getDescent());
    }/*from  w w w .  java 2s .  c  om*/
}

From source file:FlexBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    g.setColor(color);/*from   w w w.  j a  va2  s  .c  o m*/

    switch (type) {
    case TOP_LINE:
        g.drawLine(x, y, x + width - 1, y);
        break;

    case BOTTOM_LINE:
        g.drawLine(x, y + height - 1, x + width - 1, y + height - 1);
        break;

    case RECT:
        g.drawRect(x, y, width - 1, height - 1);
        break;
    }
}

From source file:cpcc.core.utils.PngImageStreamResponseTest.java

@Test
public void shouldConvertBufferedImage() throws IOException {
    BufferedImage image = new BufferedImage(2, 2, BufferedImage.TYPE_INT_ARGB);
    Graphics gr = image.getGraphics();
    gr.setColor(Color.GREEN);/*from  w  w w  . j a v  a  2  s . c  om*/
    gr.drawLine(0, 0, 1, 1);
    gr.setColor(Color.BLACK);
    gr.drawLine(1, 1, 0, 0);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ImageIO.write(image, "PNG", baos);
    byte[] expected = baos.toByteArray();

    StreamResponse response = PngImageStreamResponse.convertImageToStreamResponse(image);

    assertThat(response.getStream()).isNotNull();
    byte[] actual = IOUtils.toByteArray(response.getStream());

    assertThat(actual).isEqualTo(expected);
}

From source file:DoubleBufferWithBufferedImage.java

public void paint(Graphics g) {
    Graphics screengc = null;/*  w  w w .  j a v  a  2s . c o  m*/

    screengc = g;

    g = buffer.getGraphics();

    g.setColor(Color.blue);
    g.fillRect(0, 0, w, h);

    g.setColor(Color.red);
    for (int i = 0; i < w; i += gap)
        g.drawLine(i, 0, w - i, h);
    for (int i = 0; i < h; i += gap)
        g.drawLine(0, i, w, h - i);
    screengc.drawImage(buffer, 0, 0, null);
}

From source file:BottomBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int i;//from   www.  j  a  va  2 s  .c o m

    g.setColor(lineColor);
    for (i = 0; i < thickness; i++) {
        g.drawLine(x, y + height - i - 1, x + width, y + height - i - 1);
    }
    g.setColor(oldColor);
}

From source file:RightSideBorder.java

public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
    Color oldColor = g.getColor();
    int i;//w w w . j a  va 2  s  .co  m

    g.setColor(lineColor);
    for (i = 0; i < thickness; i++) {
        g.drawLine(x + width - i - 1, y, x + width - i - 1, y + height);
    }
    g.setColor(oldColor);
}

From source file:Main.java

public Main() {
    super("JScrollPane Demo");
    JScrollPane scrollPane = new JScrollPane(label);

    JLabel[] corners = new JLabel[4];
    for (int i = 0; i < 4; i++) {
        corners[i] = new JLabel();
        corners[i].setBackground(Color.white);
        corners[i].setOpaque(true);/*  www .  j  a v  a  2s.  com*/
    }

    JLabel rowheader = new JLabel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle rect = g.getClipBounds();
            for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) {
                g.drawLine(0, rect.y + i, 3, rect.y + i);
                g.drawString("" + (rect.y + i), 6, rect.y + i + 3);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension(25, (int) label.getPreferredSize().getHeight());
        }
    };
    rowheader.setBackground(Color.white);
    rowheader.setOpaque(true);

    JLabel columnheader = new JLabel() {

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle r = g.getClipBounds();
            for (int i = 50 - (r.x % 50); i < r.width; i += 50) {
                g.drawLine(r.x + i, 0, r.x + i, 3);
                g.drawString("" + (r.x + i), r.x + i - 10, 16);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension((int) label.getPreferredSize().getWidth(), 25);
        }
    };
    columnheader.setBackground(Color.white);
    columnheader.setOpaque(true);

    scrollPane.setRowHeaderView(rowheader);
    scrollPane.setColumnHeaderView(columnheader);
    scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]);
    scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]);
    scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]);

    getContentPane().add(scrollPane);
    setSize(400, 300);
    setVisible(true);
}

From source file:HeaderDemo.java

public HeaderDemo() {
    super("JScrollPane Demo");
    JScrollPane scrollPane = new JScrollPane(label);

    JLabel[] corners = new JLabel[4];
    for (int i = 0; i < 4; i++) {
        corners[i] = new JLabel();
        corners[i].setBackground(Color.white);
        corners[i].setOpaque(true);/* www. ja v  a 2 s.  c  om*/
    }

    JLabel rowheader = new JLabel() {
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle rect = g.getClipBounds();
            for (int i = 50 - (rect.y % 50); i < rect.height; i += 50) {
                g.drawLine(0, rect.y + i, 3, rect.y + i);
                g.drawString("" + (rect.y + i), 6, rect.y + i + 3);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension(25, (int) label.getPreferredSize().getHeight());
        }
    };
    rowheader.setBackground(Color.white);
    rowheader.setOpaque(true);

    JLabel columnheader = new JLabel() {

        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Rectangle r = g.getClipBounds();
            for (int i = 50 - (r.x % 50); i < r.width; i += 50) {
                g.drawLine(r.x + i, 0, r.x + i, 3);
                g.drawString("" + (r.x + i), r.x + i - 10, 16);
            }
        }

        public Dimension getPreferredSize() {
            return new Dimension((int) label.getPreferredSize().getWidth(), 25);
        }
    };
    columnheader.setBackground(Color.white);
    columnheader.setOpaque(true);

    scrollPane.setRowHeaderView(rowheader);
    scrollPane.setColumnHeaderView(columnheader);
    scrollPane.setCorner(JScrollPane.LOWER_LEFT_CORNER, corners[0]);
    scrollPane.setCorner(JScrollPane.LOWER_RIGHT_CORNER, corners[1]);
    scrollPane.setCorner(JScrollPane.UPPER_LEFT_CORNER, corners[2]);
    scrollPane.setCorner(JScrollPane.UPPER_RIGHT_CORNER, corners[3]);

    getContentPane().add(scrollPane);
    setSize(400, 300);
    setVisible(true);
}