Example usage for java.awt Graphics drawOval

List of usage examples for java.awt Graphics drawOval

Introduction

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

Prototype

public abstract void drawOval(int x, int y, int width, int height);

Source Link

Document

Draws the outline of an oval.

Usage

From source file:DrawRectPanel.java

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.setColor(Color.blue);//w w w . jav  a 2 s .  c  o m
    g.drawRect(10, 10, 80, 30);
    g.drawRoundRect(100, 10, 80, 30, 15, 15);

    int thickness = 4;

    for (int i = 0; i <= thickness; i++)
        g.draw3DRect(200 - i, 10 - i, 80 + 2 * i, 30 + 2 * i, true);
    for (int i = 0; i < thickness; i++)
        g.draw3DRect(200 - i, 50 - i, 80 + 2 * i, 30 + 2 * i, false);

    g.drawOval(10, 100, 80, 30);
}

From source file:com.cburch.logisim.circuit.appear.AppearancePort.java

@Override
public void paint(Graphics g, HandleGesture gesture) {
    Location location = getLocation();
    int x = location.getX();
    int y = location.getY();
    g.setColor(COLOR);//from w  w  w. j  a va 2s . c om
    if (isInput()) {
        int r = INPUT_RADIUS;
        g.drawRect(x - r, y - r, 2 * r, 2 * r);
    } else {
        int r = OUTPUT_RADIUS;
        g.drawOval(x - r, y - r, 2 * r, 2 * r);
    }
    g.fillOval(x - MINOR_RADIUS, y - MINOR_RADIUS, 2 * MINOR_RADIUS, 2 * MINOR_RADIUS);
}

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   ww  w.  j  av  a 2s.  co  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:rod_design_compute.ShowPanel.java

private void drawOtherPoint(Point point, Graphics g) {
    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    g.setColor(Color.white);/*from   w  w  w .  j a v  a  2 s. c  o m*/
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    g.setColor(Color.red);
    g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}

From source file:de.unidue.inf.is.ezdl.gframedl.tools.relations.DLObjectGraphView.java

private void setRenderers() {
    vv.getRenderContext().setVertexLabelTransformer(new Transformer<DLObject, String>() {

        @Override//from  w  ww . j  a v  a  2s  .c  o  m
        public String transform(DLObject v) {
            String result = "";
            if (v instanceof Person) {
                result = ((Person) v).getFirstName() + " " + ((Person) v).getLastName();
            }
            if (v instanceof TextDocument) {
                result = ((TextDocument) v).getTitle();
            }
            return result;
        }
    });
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeLabelRenderer(new DefaultEdgeLabelRenderer(Color.cyan));
    vv.getRenderContext().setVertexShapeTransformer(new VertexShapeFunction<DLObject>());

    vv.getRenderContext().setVertexIconTransformer(new Transformer<DLObject, Icon>() {

        @Override
        public Icon transform(final DLObject v) {
            final int size = getVertexSize(v);
            return new Icon() {

                @Override
                public int getIconHeight() {
                    return size;
                }

                @Override
                public int getIconWidth() {
                    return size;
                }

                @Override
                public void paintIcon(Component c, Graphics g, int x, int y) {
                    int halfSize = size / 2;
                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.yellow);
                    } else {
                        g.setColor(Color.lightGray);
                    }
                    g.fillOval(x, y, size, size);

                    if (vv.getPickedVertexState().isPicked(v)) {
                        g.setColor(Color.red);
                    } else {
                        g.setColor(Color.black);
                    }
                    g.drawOval(x, y, size, size);

                    int iconX = x + halfSize - 8;
                    int iconY = y + halfSize - 8;

                    if (v instanceof Person) {
                        Icons.MEDIA_AUTHOR.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                    if (v instanceof TextDocument) {
                        Icons.MEDIA_TEXT.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                    if (v instanceof Term) {
                        Icons.MEDIA_TERM.get16x16().paintIcon(c, g, iconX, iconY);
                    }
                }
            };
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(
            new PickableEdgePaintTransformer<Number>(vv.getPickedEdgeState(), Color.black, Color.black));
    vv.setBackground(Color.white);
}

From source file:rod_design_compute.ShowPanel.java

private void drawJunctionPoint(Point point, Graphics g) {
    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    g.setColor(Color.white);/*from  w ww . ja  v a2  s  .c o m*/
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    g.setColor(Color.black);
    g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}

From source file:HelloUniverse.java

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

    g.drawOval(margin, margin, diameter, diameter);
    zArea = new Rectangle(margin, margin, diameter, diameter);
    drawZPip(g2, zAngle);//from w  w  w .  j  a  v a2 s  . c  o  m

    g.drawRect(margin, margin + diameter + space, diameter, thickness); // Y
    // Wheel
    yArea = new Rectangle(margin, margin + diameter + space, margin + diameter, thickness + pipOffset);
    yBackClip = new Rectangle(margin - thickness, margin + diameter + space + thickness,
            margin + diameter + thickness * 2, thickness);
    drawYPip(g2, yAngle);

    g.drawRect(margin + diameter + space, margin, thickness, diameter); // X
    // Wheel
    xArea = new Rectangle(margin + diameter + space, margin, thickness + pipOffset, margin + diameter);
    xBackClip = new Rectangle(margin + diameter + space + thickness, margin - thickness, thickness,
            margin + diameter + thickness * 2);
    drawXPip(g2, xAngle);

}

From source file:com.jcraft.weirdx.Draw.java

private static void drawThickLine(Graphics graphics, int x1, int y1, int x2, int y2, int linewidth) {
    --linewidth;//from  w  w  w  .j a va 2  s  .  c o  m
    int lw2 = linewidth / 2;
    graphics.fillOval(x1 - lw2, y1 - lw2, linewidth, linewidth);
    if (x1 == x2 && y1 == y2)
        return;
    if (Math.abs(x2 - x1) > Math.abs(y2 - y1)) {
        int dy, srow;
        int dx, col, row, prevrow;
        if (x2 > x1)
            dx = 1;
        else
            dx = -1;
        dy = (y2 - y1) * 8192 / Math.abs(x2 - x1);
        prevrow = row = y1;
        srow = row * 8192 + 8192 / 2;
        col = x1;
        while (true) {
            if (row != prevrow) {
                graphics.drawOval(col - lw2, prevrow - lw2, linewidth, linewidth);
                prevrow = row;
            }
            graphics.drawOval(col - lw2, row - lw2, linewidth, linewidth);
            if (col == x2)
                break;
            srow += dy;
            row = srow / 8192;
            col += dx;
        }
    } else {
        int dx, scol;
        int dy, col, row, prevcol;
        if (y2 > y1)
            dy = 1;
        else
            dy = -1;
        dx = (x2 - x1) * 8192 / Math.abs(y2 - y1);
        row = y1;
        prevcol = col = x1;
        scol = col * 8192 + 8192 / 2;
        while (true) {
            if (col != prevcol) {
                graphics.drawOval(prevcol - lw2, row - lw2, linewidth, linewidth);
                prevcol = col;
            }
            graphics.drawOval(col - lw2, row - lw2, linewidth, linewidth);
            if (row == y2)
                break;
            row += dy;
            scol += dx;
            col = scol / 8192;
        }
    }
}

From source file:ScaleTest_2008.java

/**
 * Paints the test image that will be downscaled and timed by the various
 * scaling methods. A different image is rendered into each of the four
 * quadrants of this image: RGB stripes, a picture, vector art, and 
 * a black and white grid./*ww w  .j  a v a2s  .com*/
 */
private void paintOriginalImage() {
    Graphics g = originalImage.getGraphics();
    // Erase to black
    g.setColor(Color.BLACK);
    g.fillRect(0, 0, FULL_SIZE, FULL_SIZE);

    // RGB quadrant
    for (int i = 0; i < QUAD_SIZE; i += 3) {
        int x = i;
        g.setColor(Color.RED);
        g.drawLine(x, 0, x, QUAD_SIZE);
        x++;
        g.setColor(Color.GREEN);
        g.drawLine(x, 0, x, QUAD_SIZE);
        x++;
        g.setColor(Color.BLUE);
        g.drawLine(x, 0, x, QUAD_SIZE);
    }

    // Picture quadrant
    try {
        URL url = getClass().getResource("BBGrayscale.png");
        BufferedImage picture = ImageIO.read(url);
        // Center picture in quadrant area
        int xDiff = QUAD_SIZE - picture.getWidth();
        int yDiff = QUAD_SIZE - picture.getHeight();
        g.drawImage(picture, QUAD_SIZE + xDiff / 2, yDiff / 2, null);
    } catch (Exception e) {
        System.out.println("Problem reading image file: " + e);
    }

    // Vector drawing quadrant
    g.setColor(Color.WHITE);
    g.fillRect(0, QUAD_SIZE, QUAD_SIZE, QUAD_SIZE);
    g.setColor(Color.BLACK);
    g.drawOval(2, QUAD_SIZE + 2, QUAD_SIZE - 4, QUAD_SIZE - 4);
    g.drawArc(20, QUAD_SIZE + 20, (QUAD_SIZE - 40), QUAD_SIZE - 40, 190, 160);
    int eyeSize = 7;
    int eyePos = 30 - (eyeSize / 2);
    g.fillOval(eyePos, QUAD_SIZE + eyePos, eyeSize, eyeSize);
    g.fillOval(QUAD_SIZE - eyePos - eyeSize, QUAD_SIZE + eyePos, eyeSize, eyeSize);

    // B&W grid
    g.setColor(Color.WHITE);
    g.fillRect(QUAD_SIZE + 1, QUAD_SIZE + 1, QUAD_SIZE, QUAD_SIZE);
    g.setColor(Color.BLACK);
    for (int i = 0; i < QUAD_SIZE; i += 4) {
        int pos = QUAD_SIZE + i;
        g.drawLine(pos, QUAD_SIZE + 1, pos, FULL_SIZE);
        g.drawLine(QUAD_SIZE + 1, pos, FULL_SIZE, pos);
    }

    originalImagePainted = true;
}

From source file:rod_design_compute.ShowPanel.java

private void drawBasePoint(Point point, Graphics g) {
    int x = toScreenX(point.X);
    int y = toScreenY(point.Y);

    int lengthTri = 4 * radiusBase;
    int x1 = (int) (x - lengthTri * Math.sin(Math.toRadians(30)));
    int y1 = (int) (y + lengthTri * Math.cos(Math.toRadians(30)));
    int x2 = (int) (x + lengthTri * Math.sin(Math.toRadians(30)));
    int y2 = (int) (y + lengthTri * Math.cos(Math.toRadians(30)));

    g.drawLine(x, y, x1, y1);/*from   w  ww  .jav  a 2 s.com*/
    g.drawLine(x, y, x2, y2);
    g.drawLine(x1 - radiusBase, y1, x2 + radiusBase, y2);

    g.drawLine(x1, y1, x1 - radiusBase, y1 + radiusBase);
    g.drawLine(x1 + radiusBase, y1, x1 + radiusBase - radiusBase, y1 + radiusBase);
    g.drawLine(x1 + 2 * radiusBase, y1, x1 + 2 * radiusBase - radiusBase, y1 + radiusBase);
    g.drawLine(x1 + 3 * radiusBase, y1, x1 + 3 * radiusBase - radiusBase, y1 + radiusBase);
    g.drawLine(x1 + 4 * radiusBase, y1, x1 + 4 * radiusBase - radiusBase, y1 + radiusBase);

    g.setColor(Color.white);
    g.fillOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
    g.setColor(Color.black);
    g.drawOval(x - radiusBase, y - radiusBase, radiusBase * 2, radiusBase * 2);
}