Java Code Examples for java.awt.Graphics2D.drawOval()

The following are Jave code examples for showing how to use drawOval() of the java.awt.Graphics2D class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jmt   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * It draw a temporary point when a point is moved in another place
 * @param g The graphic object
 * @param p The position of the point
 * @param c The color of the point
 * @param size The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
	g.setColor(c);

	int fontSize = 7 + pointSize;
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);
	double x = Math.max((p.getX() - tran_x) / scale, 0);
	double y = Math.max((-p.getY() + tran_y) / scale, 0);
	double X = (x * scale) + tran_x;
	double Y = -((y * scale) - tran_y);

	g.drawString("(" + format2Dec.format(x) + ", " + format2Dec.format(y) + ")", (int) (X - (fontSize * 3)), (int) Y - 5 - pointSize);

	g.drawOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);

	g.setColor(Color.GRAY);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);
	g.fillOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);
	g.setComposite(oldComp);

}
 
Example 2
Project: JGraphix   File: JGraphix_Example_3.java   View Source Code Vote up 6 votes
public static void main(String[] args) throws InterruptedException {
	DrawFrame df = DrawFrame.create("example3", 800, 600);
	Graphics2D g = df.getGraphics2D();

	int n = 50;

	g.setFont(new Font("Dialog", Font.PLAIN, 16));
	g.drawString("Some Text", 10, 20);

	double incX = (double) df.getW() / n;
	double incY = (double) df.getH() / n;

	g.setStroke(new BasicStroke(1));
	g.setColor(Color.BLACK);
	g.drawOval(50, 50, 200, 100);

	for (int i = 1; i <= n; i++) {
		int x1 = (int) Math.round(i * incX);
		int y1 = 0;
		int x2 = (int) Math.round(incX * (n - i));
		int y2 = (int) Math.round(i * incY);
		g.drawLine(x1, y1, x2, y2);
	}

	df.refresh();
}
 
Example 3
Project: UtilsMaven   File: VerificationCodeImage.java   View Source Code Vote up 6 votes
/**
 * 随机画点
 *
 * @param image 图片
 */
private void drawPoint(BufferedImage image) {
    if (this.pointPower == -1) {
        return;
    }
    Random r = new Random();
    Graphics2D g2 = (Graphics2D) image.getGraphics();
    int max = this.w * this.h / this.pointPower;
    for (int i = 0; i < max; i++) {
        int x = r.nextInt(w);
        int y = r.nextInt(h);
        g2.setStroke(new BasicStroke(1.5F));
        g2.setColor(this.randomColor());
        g2.drawOval(x, y, 1, 1);
    }
    g2.dispose();
}
 
Example 4
Project: QN-ACTR-Release   File: PainterConvex2D.java   View Source Code Vote up 6 votes
/**
 * It draw a temporary point when a point is moved in another place
 * @param g The graphic object
 * @param p The position of the point
 * @param c The color of the point
 * @param size The size of the point
 */
public void drawShadowPoint(Graphics2D g, Point p, Color c, int size) {
	g.setColor(c);

	int fontSize = 7 + pointSize;
	Font f = new Font("Arial", Font.PLAIN, fontSize);
	g.setFont(f);
	double x = Math.max((p.getX() - tran_x) / scale, 0);
	double y = Math.max((-p.getY() + tran_y) / scale, 0);
	double X = (x * scale) + tran_x;
	double Y = -((y * scale) - tran_y);

	g.drawString("(" + format2Dec.format(x) + ", " + format2Dec.format(y) + ")", (int) (X - (fontSize * 3)), (int) Y - 5 - pointSize);

	g.drawOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);

	g.setColor(Color.gray);
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.3f);
	g.setComposite(alphaComp);
	g.fillOval((int) X - (((size / 2))), (int) Y - (((size / 2))), size, size);
	g.setComposite(oldComp);

}
 
Example 5
Project: jaer   File: LabyrinthTableTiltControllerGUI.java   View Source Code Vote up 6 votes
@Override
public void paint(Graphics g) {
    final int r = 6;
    super.paint(g);

    // paint cross hairs to show center
    Graphics2D g2 = (Graphics2D) calibrationPanel.getGraphics();
    int w = calibrationPanel.getWidth(), h = calibrationPanel.getHeight();
    g2.setColor(Color.gray);
    g2.drawLine(w / 2, 0, w / 2, h);
    g2.drawLine(0, h / 2, w, h / 2);
    g2.setColor(Color.red) ;
    float x=w/2+w/2*currentPanTiltRad.x/controller.getTiltLimitRad();
    float y=h/2+h/2*(-currentPanTiltRad.y/controller.getTiltLimitRad());
    final int s=20;
    g2.drawOval((int)x-s/2, (int)y-s/2, s, s);

    trajectory.paint();
}
 
Example 6
Project: openjdk-jdk10   File: UpdatePopupMenu.java   View Source Code Vote up 6 votes
private Image createSystemTrayIconImage() {
    final BufferedImage trayImage = new BufferedImage(
            imageSize,
            imageSize,
            BufferedImage.TYPE_INT_ARGB);

    final Graphics2D imageGraphics = (Graphics2D) trayImage.getGraphics();

    imageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);

    imageGraphics.setColor(new Color(255, 255, 255, 0));
    imageGraphics.fillRect(0, 0, trayImage.getWidth(),
            trayImage.getHeight());

    imageGraphics.setColor(Color.green);

    int imageWidth = trayImage.getWidth() - 2 * imageInset;
    int imageHeight = trayImage.getHeight() - 2 * imageInset;

    imageGraphics.fillOval(imageInset, imageInset, imageWidth, imageHeight);
    imageGraphics.setColor(Color.darkGray);
    imageGraphics.drawOval(imageInset, imageInset, imageWidth, imageHeight);

    return trayImage;
}
 
Example 7
Project: Mafia   File: PlayerLocal.java   View Source Code Vote up 6 votes
@Override
protected void onRender(Graphics2D g, Game game) {
	//Pointer outline////
	if(pointerOutlineStage > 0) {
		Stroke normalStroke = g.getStroke();
		g.setStroke(new BasicStroke(POINTER_SECONDARY_OUTLINE_WIDTH));
		
		
		int colorAlpha = (int) (255 * pointerOutlineStage);
		g.setColor(new Color(Pointer.POINTER_SECONDARY_COLOR.getRed(), Pointer.POINTER_SECONDARY_COLOR.getGreen(), Pointer.POINTER_SECONDARY_COLOR.getBlue(), colorAlpha));
		
		int outlineRadius = Player.SELECT_POINTER_SECONDARY_DISTANCE_LIMIT;
		g.drawOval((int) x - outlineRadius, (int) y - (height / 2) - outlineRadius, outlineRadius * 2, outlineRadius * 2);
		
		
		g.setStroke(normalStroke);
	}
}
 
Example 8
Project: java-course   File: Circle.java   View Source Code Vote up 6 votes
/**
 * {@inheritDoc}
 */
@Override
public void draw(Graphics g, RectBounds rect) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
            RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    g2.setColor(color);
    g2.drawOval(center.x - radius - rect.getMinX(), center.y - radius
            - rect.getMinY(), 2 * radius, 2 * radius);
}
 
Example 9
Project: java-course   File: Krug.java   View Source Code Vote up 6 votes
public void iscrtaj(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
            RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    if (bojaPozadine != null) {
        g2.setColor(bojaPozadine);
        g2.fillOval(centar.x - radius, centar.y - radius, radius * 2,
                radius * 2);
    }

    g2.setColor(bojaObruba);
    g2.drawOval(centar.x - radius, centar.y - radius, radius * 2,
            radius * 2);

}
 
Example 10
Project: java-course   File: Krug.java   View Source Code Vote up 6 votes
public void iscrtaj(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;

    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_RENDERING,
            RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
            RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING,
            RenderingHints.VALUE_COLOR_RENDER_QUALITY);
    if (bojaPozadine != null) {
        g2.setColor(bojaPozadine);
        g2.fillOval(centar.x - radius, centar.y - radius, radius * 2,
                radius * 2);
    }

    g2.setColor(bojaObruba);
    g2.drawOval(centar.x - radius, centar.y - radius, radius * 2,
            radius * 2);

}
 
Example 11
Project: VISNode   File: JConnectorPoint.java   View Source Code Vote up 5 votes
@Override
protected void paintComponent(Graphics g) {
    if (!isEnabled()) {
        return;
    }
    Graphics2D g2d = (Graphics2D) g.create();
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setColor(color);
    Point topLeft = getTopLeftCorner();
    g2d.fillOval(topLeft.x, topLeft.y, SIZE.width, SIZE.height);
    g2d.setColor(UIHelper.getColor("ConnectorPoint.border"));
    g2d.drawOval(topLeft.x, topLeft.y, SIZE.width, SIZE.height);
    g2d.dispose();
}
 
Example 12
Project: Cognizant-Intelligent-Test-Scripter   File: Canvas.java   View Source Code Vote up 5 votes
public static void paintOffset(Graphics2D g2d, Point p) {

        g2d.setColor(Color.red);
        int r = 4, x = p.x, y = p.y, dz = 4;
        g2d.setStroke(STROKE_OFFSET);
        g2d.drawLine(x, y - (r + dz), x, y + (r + dz));// --
        g2d.drawLine(x - (r + dz), y, x + (r + dz), y);// |
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setStroke(STROKE_OFFSET);
        g2d.drawOval(x - r, y - r, 2 * r, 2 * r);
        g2d.dispose();

    }
 
Example 13
Project: openjdk-jdk10   File: PopupMenuLeakTest.java   View Source Code Vote up 5 votes
private static Image createTrayIconImage() {
    /**
     * Create a small image of a red circle to use as the icon for the tray icon
     */
    int trayIconImageSize = 32;
    final BufferedImage trayImage = new BufferedImage(trayIconImageSize, trayIconImageSize, BufferedImage.TYPE_INT_ARGB);
    final Graphics2D trayImageGraphics = (Graphics2D) trayImage.getGraphics();

    trayImageGraphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    trayImageGraphics.setColor(new Color(255, 255, 255, 0));
    trayImageGraphics.fillRect(0, 0, trayImage.getWidth(), trayImage.getHeight());

    trayImageGraphics.setColor(Color.red);

    int trayIconImageInset = 4;
    trayImageGraphics.fillOval(trayIconImageInset,
            trayIconImageInset,
            trayImage.getWidth() - 2 * trayIconImageInset,
            trayImage.getHeight() - 2 * trayIconImageInset);

    trayImageGraphics.setColor(Color.darkGray);

    trayImageGraphics.drawOval(trayIconImageInset,
            trayIconImageInset,
            trayImage.getWidth() - 2 * trayIconImageInset,
            trayImage.getHeight() - 2 * trayIconImageInset);

    return trayImage;
}
 
Example 14
Project: ants   File: SimpleGUIComponent.java   View Source Code Vote up 5 votes
public boolean paint(Graphics g) {
	if (isMovePresent()) {
		prepareDeltas();
	}
	
	boolean ret = !isMovePresent();
	
	Graphics2D g2 = (Graphics2D)g;
	try {
		if (TEAM_COLOR != null) {
			g2.setColor(TEAM_COLOR);
			g2.setStroke(new BasicStroke(3));
			g2.drawOval((x * MAGNIFICATIONX) + dx, (y * MAGNIFICATIONY) + dy, MAGNIFICATIONX, MAGNIFICATIONY);
		}
		g2.drawImage(ret ? getImageToDraw() : getFinalImageToDraw(), (x * MAGNIFICATIONX) + dx, (y * MAGNIFICATIONY) + dy, MAGNIFICATIONX, MAGNIFICATIONY, null);
	} catch (Exception e) {
	}
	if ((x * MAGNIFICATIONX) + dx == (moveX * MAGNIFICATIONX)) {
		dx = 0;
		x = moveX;
	}
	if ((y * MAGNIFICATIONY) + dy == (moveY * MAGNIFICATIONY)) {
		dy = 0;
		y = moveY;
	}
	if ((x * MAGNIFICATIONX) + dx == (moveX * MAGNIFICATIONX) && (y * MAGNIFICATIONY) + dy == (moveY * MAGNIFICATIONY)) {
		setLocation(moveX, moveY);
	}
	
	return ret;
}
 
Example 15
Project: Pet-Supply-Store   File: ImageCreator.java   View Source Code Vote up 5 votes
private static void makeOval(Graphics2D graphics, ImageSize maxSize, Random rand) {
	switchColor(graphics, rand);
	
	int x = rand.nextInt(maxSize.getWidth());
	int y = rand.nextInt(maxSize.getHeight());
	int width = rand.nextInt(maxSize.getWidth() - x) + 1;
	int height = rand.nextInt(maxSize.getHeight() - y) + 1;

	if (rand.nextBoolean()) {
		graphics.fillOval(x, y, width, height);
	}

	graphics.drawOval(x, y, width, height);
}
 
Example 16
Project: freecol   File: FreeColActionUI.java   View Source Code Vote up 5 votes
/**
* Creates an icon for symbolizing the recording of a {@code KeyStroke}.
* @return The {@code ImageIcon}.
*/
public static ImageIcon getRecordImage() {
    BufferedImage bi = new BufferedImage(9, 9, BufferedImage.TYPE_INT_ARGB);
    Graphics2D g = bi.createGraphics();
    g.setColor(Color.RED);
    g.fillOval(0, 0, 9, 9);
    g.setColor(Color.BLACK);
    g.drawOval(0, 0, 9, 9);
    g.dispose();
    return new ImageIcon(bi);
}
 
Example 17
Project: hearthstone   File: PartidaView.java   View Source Code Vote up 5 votes
public void pintarLinhaEvento(Graphics2D g2, Point origem, Point destino) {
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
    g2.setColor(Color.red);
    g2.drawLine(origem.x, origem.y, destino.x, destino.y);
    g2.setStroke(new BasicStroke(5, BasicStroke.JOIN_ROUND, BasicStroke.CAP_ROUND));
    g2.drawOval(destino.x - 25, destino.y - 25, 50, 50);
    g2.fillOval(destino.x - 10, destino.y - 10, 20, 20);
}
 
Example 18
Project: openjdk-jdk10   File: MultiGradientTest.java   View Source Code Vote up 4 votes
public void paintComponent(Graphics g) {
    Graphics2D g2d = (Graphics2D)g.create();

    int w = getWidth();
    int h = getHeight();
    g2d.setColor(Color.black);
    g2d.fillRect(0, 0, w, h);

    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                         antialiasHint);
    g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                         renderHint);

    g2d.transform(transform);
    g2d.setPaint(paint);

    switch (shapeType) {
    default:
    case RECT:
        g2d.fillRect(0, 0, w, h);
        break;

    case ELLIPSE:
        g2d.fillOval(0, 0, w, h);
        break;

    case MULTIPLE:
        g2d.fillRect(0, 0, w/2, h/2);
        g2d.fillOval(w/2, 0, w/2, h/2);
        g2d.drawOval(0, h/2, w/2, h/2);
        g2d.drawLine(0, h/2, w/2, h);
        g2d.drawLine(0, h, w/2, h/2);
        Polygon p = new Polygon();
        p.addPoint(w/2, h);
        p.addPoint(w, h);
        p.addPoint(3*w/4, h/2);
        g2d.fillPolygon(p);
        break;
    }

    switch (paintType) {
    default:
    case BASIC:
    case LINEAR:
        g2d.setColor(Color.white);
        g2d.fillRect(startX-1, startY-1, 2, 2);
        g2d.drawString("1", startX, startY + 12);
        g2d.fillRect(endX-1, endY-1, 2, 2);
        g2d.drawString("2", endX, endY + 12);
        break;

    case RADIAL:
        g2d.setColor(Color.white);
        g2d.fillRect(ctrX-1, ctrY-1, 2, 2);
        g2d.drawString("C", ctrX, ctrY + 12);
        g2d.fillRect(focusX-1, focusY-1, 2, 2);
        g2d.drawString("F", focusX, focusY + 12);
        break;
    }

    g2d.dispose();
}
 
Example 19
Project: jaer   File: JAERDataViewer.java   View Source Code Vote up 4 votes
private synchronized void drawData(Graphics2D g2) {
    int n;
    int [] x;
    int [] y;
    int length = 0;
    g2.setStroke(new BasicStroke());
      for(Iterator<GraphData> it = currentGraphs.values().iterator(); it.hasNext(); ) {
         GraphData dt = it.next();
         g2.setColor(dt.Color);
         synchronized (dt.Y) {
         
             switch(dt.DataType) {
                 case YScrolling:
                     length = Math.min(this.getWidth(), dt.Y.size());
                     x = new int[length];
                     y = new int[length];
                     int l = dt.Y.size() - length;
                     for(n = 0; n < length;n++ ) {
                         x[n] = n;
                         y[n] = (int)(this.getHeight()- (dt.Y.get(l + n) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
                     }
                     break;

                 case YScaling:
                     length = this.getWidth();
                     x = new int[length];
                     y = new int[length];
                     double scale = ((double) dt.Y.size() ) / (double)length;
                     for(n = 0; n < length ;n++ ) {
                         x[n] = n;
                         y[n] = (int)(this.getHeight()- (dt.Y.get((int)(n*scale)) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
                     }
                     break;

                 case XY:
                     assert(dt.X.size() == dt.Y.size());
                     length = dt.X.size();
                     x = new int[length];
                     y = new int[length];

                     for(n = 0; n < length;n++ ) {
                         x[n] = (int)((dt.X.get(n) - (double)getMinX())/(double)(max_x - getMinX())*this.getWidth());
                         y[n] = (int)(this.getHeight()- (dt.Y.get(n) - (double)getMinY())/(double)(max_y - getMinY())*this.getHeight());
                     }
                     break;
                 default:
                     length = 0;
                     x = new int[length];
                     y = new int[length];
             }
             if(dt.Style == LineStyle.Point || dt.Style == LineStyle.PointLine) {
                 for(n = 0; n < length ;n++ ) {
                     g2.setStroke(new BasicStroke(3.0f));
                     g2.drawOval(x[n] - 2, y[n] -2, 4 , 4);
                     g2.setStroke(new BasicStroke(1.0f));
                 }
             }

             if(dt.Style == LineStyle.Line || dt.Style == LineStyle.PointLine) {
                g2.drawPolyline(x, y, length);    
             }
         }
      }
}
 
Example 20
Project: FCat   File: CaptchaUtil.java   View Source Code Vote up 4 votes
public static BufferedImage createWeak(int width, int height, String captchaValue) {
	if (LOG.isDebugEnabled()) {
		LOG.debug("createWeak(int width, int height, String captchaValue) width=" + width + " height=" + height + " captchaValue=" + captchaValue);
	}

	if (captchaValue == null) {
		throw new NullPointerException("captchaValue=" + captchaValue);
	}
	width = widthFix(width);
	height = heightFix(height);

	BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);

	Graphics2D graphic = bufferedImage.createGraphics();
	graphic.setColor(Color.WHITE);
	graphic.fillRect(0, 0, width, height);
	// graphic.setColor(Color.BLACK);
	// graphic.drawRect(0, 0, width - 1, height - 1);
	// (int) (height * 0.8)
	Font font = new Font("Arial", Font.PLAIN + Font.ITALIC, 30);
	graphic.setFont(font);

	// FontRenderContext fontRenderContext = graphic.getFontRenderContext();
	// Rectangle2D rectangle2D =
	// font.getStringBounds(String.valueOf(captchaValue.charAt(0)),
	// fontRenderContext);
	// rectangle2D.getWidth();

	int captchaValueLength = captchaValue.length();
	int splitSize = 2;
	int xx = 0;
	int widthChar = (width - (captchaValueLength * splitSize)) / captchaValueLength;
	for (int i = 0; i < captchaValueLength; i++) {
		xx = i * widthChar + splitSize;
		graphic.setColor(new Color(MathUtil.RANDOM.nextInt(110), MathUtil.RANDOM.nextInt(110), MathUtil.RANDOM.nextInt(110)));
		graphic.drawString(String.valueOf(captchaValue.charAt(i)), xx, (int) (height * 0.8) + MathUtil.RANDOM.nextInt(6));
	}

	// 加点
	for (int i = 0; i < (width + height); i++) {
		graphic.setColor(new Color(MathUtil.RANDOM.nextInt(255), MathUtil.RANDOM.nextInt(255), MathUtil.RANDOM.nextInt(255)));
		graphic.drawOval(MathUtil.RANDOM.nextInt(width), MathUtil.RANDOM.nextInt(height), 1, 1);
	}

	// 加线
	for (int i = 0; i < 4; i++) {
		graphic.setColor(new Color(MathUtil.RANDOM.nextInt(255), MathUtil.RANDOM.nextInt(255), MathUtil.RANDOM.nextInt(255)));
		graphic.drawLine(0, MathUtil.RANDOM.nextInt(height), width, MathUtil.RANDOM.nextInt(height));
	}
	return bufferedImage;
}