当前位置: 首页>>代码示例>>Java>>正文


Java Graphics2D.drawPolygon方法代码示例

本文整理汇总了Java中java.awt.Graphics2D.drawPolygon方法的典型用法代码示例。如果您正苦于以下问题:Java Graphics2D.drawPolygon方法的具体用法?Java Graphics2D.drawPolygon怎么用?Java Graphics2D.drawPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.Graphics2D的用法示例。


在下文中一共展示了Graphics2D.drawPolygon方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: drawArea

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * This function draw the area among the axis and the point of the convex
 * hull
 * 
 * @param g
 *            The graphic object
 * @param allConvex
 *            The vector with the points of the convex hull
 * @param allDominants
 *            The vector with the dominant points
 * @param area
 *            The filter area
 * @param maskedoff
 *            The vector with the masked-off points
 */
public void drawArea(Graphics2D g, Vector<Point2D> allConvex, Color color) {
	Polygon poly = new Polygon();
	DPoint p;

	poly.addPoint(plane.getTrueX(0), plane.getTrueY(0));
	poly.addPoint(plane.getTrueX(xMaxValue), plane.getTrueY(0));
	// Add the point a the polygon for paint the convex area
	for (int i = 0; i < allConvex.size(); i++) {
		p = (DPoint) allConvex.get(i);
		poly.addPoint(plane.getTrueX(p.getX()), plane.getTrueY(p.getY()));
	}
	poly.addPoint(plane.getTrueX(0), plane.getTrueY(yMaxValue));

	g.setStroke(LINES);
	g.setColor(color);
	g.drawPolygon(poly);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:33,代码来源:Convex2DGraph.java

示例2: drawDragArea

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draw a semi-trasparet area
 * @param g The graphic object
 * @param dragPoint The first point
 * @param beginPoint The second point
 * @param c The color of the area
 */
public void drawDragArea(Graphics2D g, Point dragPoint, Point beginPoint, Color c) {
	g.setColor(c);

	Polygon poly = new Polygon();

	poly.addPoint((int) beginPoint.getX(), (int) beginPoint.getY());
	poly.addPoint((int) beginPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) dragPoint.getY());
	poly.addPoint((int) dragPoint.getX(), (int) beginPoint.getY());

	//Set the widths of the shape's outline
	Stroke oldStro = g.getStroke();
	Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
	g.setStroke(stroke);
	g.drawPolygon(poly);
	g.setStroke(oldStro);

	//Set the trasparency of the iside of the rectangle
	Composite oldComp = g.getComposite();
	Composite alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f);
	g.setComposite(alphaComp);
	g.fillPolygon(poly);
	g.setComposite(oldComp);

}
 
开发者ID:max6cn,项目名称:jmt,代码行数:33,代码来源:PainterConvex2D.java

示例3: paint

import java.awt.Graphics2D; //导入方法依赖的package包/类
public void paint(Graphics g) {
  paintBackground(g);
  if (polygon != null && polygon.npoints > 0) {
    final Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(Color.white);
    g2d.setComposite(
      AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5F));
    g2d.fill(polygon);

    if (selected >= 0 && selected < polygon.xpoints.length) {
      g2d.setColor(Color.red);
      int x = polygon.xpoints[selected];
      int y = polygon.ypoints[selected];
      g2d.fillOval(x - 10, y - 10, 20, 20);
    }

    g2d.setComposite(AlphaComposite.SrcAtop);
    g2d.setColor(Color.black);
    g2d.setStroke(new BasicStroke(2.0F));
    g2d.drawPolygon(polygon);
  }
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:24,代码来源:PolygonEditor.java

示例4: drawPolygon

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draw a polygon which passes through all the points drawn by the user.
 *
 * @param g2d        the graphics object
 * @param polygon    the polygon to be drawn on the interface
 * @param color      the color of the polygon
 * @param dashedLine true = the line used for drawing the polygon will be dashed; false = the line will be solid/plain
 */
public static void drawPolygon(Graphics2D g2d, Polygon polygon, Color color, boolean dashedLine) {
    g2d.setStroke(dashedLine ? getDashedStroke() : new BasicStroke(0));

    if (polygon.npoints > 0) {
        g2d.setColor(color);
        g2d.drawPolygon(polygon);

        // make the line thicker
        g2d.setStroke(new BasicStroke(2));

        for (int index = 0; index < polygon.npoints; index++) {
            g2d.drawLine(polygon.xpoints[index], polygon.ypoints[index],
                    polygon.xpoints[index], polygon.ypoints[index]);
        }
    }

    g2d.setStroke(new BasicStroke(0));
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:27,代码来源:DrawOptions.java

示例5: drawInstance

import java.awt.Graphics2D; //导入方法依赖的package包/类
private void drawInstance(InstancePainter painter, boolean isGhost) {
	Graphics2D g = (Graphics2D) painter.getGraphics().create();
	Location loc = painter.getLocation();
	g.translate(loc.getX(), loc.getY());

	Direction from = painter.getAttributeValue(StdAttr.FACING);
	int degrees = Direction.EAST.toDegrees() - from.toDegrees();
	double radians = Math.toRadians((degrees + 360) % 360);
	g.rotate(radians);

	GraphicsUtil.switchToWidth(g, Wire.WIDTH);
	if (!isGhost && painter.getShowState()) {
		g.setColor(painter.getPort(0).getColor());
	}
	g.drawLine(0, 0, 5, 0);

	GraphicsUtil.switchToWidth(g, 1);
	if (!isGhost && painter.shouldDrawColor()) {
		BitWidth width = painter.getAttributeValue(StdAttr.WIDTH);
		g.setColor(Value.repeat(Value.TRUE, width.getWidth()).getColor());
	}
	g.drawPolygon(new int[] { 6, 14, 6 }, new int[] { -8, 0, 8 }, 3);

	g.dispose();
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:26,代码来源:Power.java

示例6: test

import java.awt.Graphics2D; //导入方法依赖的package包/类
private static void test(final Graphics2D g, final int[] arr) {
    g.drawPolygon(arr, arr, arr.length);
    g.drawPolygon(new Polygon(arr, arr, arr.length));
    g.fillPolygon(arr, arr, arr.length);
    g.fillPolygon(new Polygon(arr, arr, arr.length));
    g.drawPolyline(arr, arr, arr.length);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:8,代码来源:Test8004821.java

示例7: drawPolygon

import java.awt.Graphics2D; //导入方法依赖的package包/类
/**
 * Draw the outer box of the object; a rectangle which is resized to the
 * proper image size.
 *
 * @param g2d the graphics object
 * @return the rectangle drawn on the image
 */
private void drawPolygon(Graphics2D g2d) {

    java.awt.Polygon polygon = new Polygon(((ObjectPolygon) currentObject).getPolygon().xpoints,
            ((ObjectPolygon) currentObject).getPolygon().ypoints,
            ((ObjectPolygon) currentObject).getPolygon().npoints);

    // shift the polygon with the bordered added
    for (int index = 0; index < polygon.npoints; index++) {
        polygon.xpoints[index] -= displayBox.x;
        polygon.ypoints[index] -= displayBox.y;
    }

    // compute the position of the object box, to be displayed
    polygon = resize.originalToResized(polygon);

    g2d.setColor(objectColor);

    g2d.drawPolygon(polygon);

    // make the line thicker
    g2d.setStroke(new BasicStroke(3));

    // draw the points of the polygon
    for (int index = 0; index < polygon.npoints; index++) {
        g2d.drawLine(polygon.xpoints[index], polygon.ypoints[index],
                polygon.xpoints[index], polygon.ypoints[index]);
    }

    // reset the thicknes of the line
    g2d.setStroke(new BasicStroke(0));
}
 
开发者ID:buni-rock,项目名称:Pixie,代码行数:39,代码来源:BoundingBoxWindow.java

示例8: DrawComplexPath

import java.awt.Graphics2D; //导入方法依赖的package包/类
private boolean DrawComplexPath(Graphics2D g, int l, int t) {
        String[] dist = getPath().split(",");
        int dl = dist.length;
        if (dl < 3) {
            g.drawString("?", l, t);
            return false;
        }
        if (dl % 2 > 0) {
            String[] tmp = new String[dl + 1];
            tmp[dl] = "0";
            dist = tmp;
            dl = dist.length;
        }
        int tam = dl / 2;
        int xPoints[] = new int[tam];
        int yPoints[] = new int[tam];
        try {
            int y = 0;
            for (int i = 0; i < tam; i++) {
                xPoints[i] = Expr(dist[y++].trim());
                yPoints[i] = Expr(dist[y++].trim());
//                xPoints[i] = l + Integer.valueOf(dist[y++].trim());
//                yPoints[i] = t + Integer.valueOf(dist[y++].trim());
            }
        } catch (Exception x) {
            g.drawString("?", l, t);
            return false;
        }
        if (isFill()) {
            g.fillPolygon(xPoints, yPoints, tam);
        } else {
            g.drawPolygon(xPoints, yPoints, tam);
        }
        return true;
    }
 
开发者ID:chcandido,项目名称:brModelo,代码行数:36,代码来源:baseDrawerItem.java

示例9: criaQuadrado

import java.awt.Graphics2D; //导入方法依赖的package包/类
public BufferedImage criaQuadrado(BufferedImage img, PosicoesDTO posicoes) {
	Graphics graphics = img.getGraphics();
	Graphics2D graphics2d = (Graphics2D) graphics.create();
	graphics2d.setStroke(new BasicStroke(4));
	graphics2d.setColor(Color.BLUE);

	int x1 = posicoes.getX1();
	int x2 = posicoes.getX2();
	int y1 = posicoes.getY1();
	int y2 = posicoes.getY2();

	graphics2d.drawPolygon(new int[] { x1, x1, x2, x2 }, new int[] { y1, y2, y2, y1 }, 4);
	graphics2d.dispose();
	return img;
}
 
开发者ID:nbfontana,项目名称:pdi,代码行数:16,代码来源:Quadrado.java

示例10: paintComponent

import java.awt.Graphics2D; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g1){
	if(Main.config.showGraph){
		try{
			Graphics2D g = (Graphics2D)g1;
			g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
			if(ColorManager.transparency){
				g.setColor(ColorManager.transparent);
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getBackgroundOpacity()));
				g.setColor(Main.config.getBackgroundColor());
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getBackgroundOpacity()));
			}else{
				g.setColor(Main.config.getBackgroundColor());
				g.fillRect(0, 0, this.getWidth(), this.getHeight());
				g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0F));
			}
			Polygon poly = new Polygon();
			poly.addPoint(this.getWidth() - SizeManager.graphOffset - 2, this.getHeight() - SizeManager.graphOffset);
			for(int i = 1; i <= values.size(); i++){
				int px = (int) (SizeManager.graphOffset + 2 + ((double)(this.getWidth() - SizeManager.graphOffset * 2 - 4) / (double)(Main.config.backlog - 1)) * (Main.config.backlog - i));
				int py = (int) (this.getHeight() - SizeManager.graphOffset - ((float)(this.getHeight() - SizeManager.graphOffset * 2) * ((float)values.get(i - 1) / (float)maxval)));
				poly.addPoint(px, py);
				if(i == values.size()){
					poly.addPoint(px, this.getHeight() - SizeManager.graphOffset);
				}
			}
			g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, Main.config.getForegroundOpacity()));
			if(Main.config.graphAvg){
				int y = (int) (this.getHeight() - SizeManager.graphOffset - ((float)(this.getHeight() - SizeManager.graphOffset * 2) * (Main.avg / (float)maxval)));
				g.setColor(Main.config.getForegroundColor().darker());
				g.setStroke(avgstroke);
				g.drawLine(SizeManager.graphOffset + 2, y, this.getWidth() - SizeManager.graphOffset - 2, y);
			}
			g.setStroke(line);
			g.setColor(ColorManager.alphaAqua);
			g.fillPolygon(poly);
			g.setColor(Main.config.getForegroundColor());
			g.drawPolygon(poly);
			g.drawImage(ColorManager.graph_upper_left,   2, 2, 2 + SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_lower_left,   2, this.getHeight() - 3 - SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, this.getHeight() - 3, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_upper_right,  this.getWidth() - 3 - SizeManager.graphImageSize, 2, this.getWidth() - 3, 2 + SizeManager.graphImageSize, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_lower_right,  this.getWidth() - 3 - SizeManager.graphImageSize, this.getHeight() - 3 - SizeManager.graphImageSize, this.getWidth() - 3, this.getHeight() - 3, 0, 0, 4, 4, this);
			g.drawImage(ColorManager.graph_side_left,    2, 2 + SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, this.getHeight() - 3 - SizeManager.graphImageSize, 0, 0, 4, 56, this);
			g.drawImage(ColorManager.graph_upper_middle, 2 + SizeManager.graphImageSize, 2, this.getWidth() - 3 - SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, 0, 0, 46, 4, this);
			g.drawImage(ColorManager.graph_lower_middle, 2 + SizeManager.graphImageSize, this.getHeight() - 3 - SizeManager.graphImageSize, this.getWidth() - 3 - SizeManager.graphImageSize, this.getHeight() - 3, 0, 0, 46, 4, this);
			g.drawImage(ColorManager.graph_side_right,   this.getWidth() - 3 - SizeManager.graphImageSize, 2 + SizeManager.graphImageSize, this.getWidth() - 3, this.getHeight() - 3 - SizeManager.graphImageSize, 0, 0, 4, 56, this);
		}catch(NullPointerException e){
			//catch but do not solve, this is caused by the race
			//condition. However adding synchronisation would impact
			//performance more then it is worth
		}
	}
}
 
开发者ID:RoanH,项目名称:KeysPerSecond,代码行数:57,代码来源:GraphPanel.java

示例11: main

import java.awt.Graphics2D; //导入方法依赖的package包/类
public static void main(String[] args) {
	DrawFrame df = DrawFrame.create("MyDrawing", 200, 300);
	Graphics2D g = df.getGraphics2D();
	
	float linewidth = 5.0f;	// line width = 5 pixels
	g.setStroke(new BasicStroke(linewidth));
	
	g.setColor(Color.BLUE);
	g.drawLine(40, 10, 10, 40);
	g.draw(new Line2D.Double(70.2, 10.3, 100.4, 40.5));

	g.fillOval(10, 60, 30, 30);
	g.drawOval(60, 60, 30, 30);
	g.fillRoundRect(110, 60, 30, 30, 10, 10);
	g.drawRoundRect(160, 60, 30, 30, 10, 10);

	g.setColor(Color.GREEN.darker());
	g.fillArc(10, 110, 30, 30, 45, 240);
	g.fillArc(60, 110, 30, 30, 45 + 240, 360 - 240);
	g.fillArc(110, 110, 30, 30, 90, 270);
	g.fillArc(160, 110, 30, 30, 270, 270);

	g.setColor(Color.MAGENTA);
	g.drawArc(10, 160, 30, 30, 45, 240);
	g.drawArc(60, 160, 30, 30, 45 + 240, 360 - 240);
	g.drawArc(110, 160, 30, 30, 90, 270);
	g.drawArc(160, 160, 30, 30, 270, 270);

	g.setColor(Color.ORANGE);
	g.fillPolygon(new int[] { 10, 40, 10, 40 }, new int[] { 210, 210, 240, 240 }, 4);
	g.drawPolygon(new int[] { 60, 90, 60, 90 }, new int[] { 210, 210, 240, 240 }, 4);
	g.drawPolyline(new int[] { 110, 140, 110, 140 }, new int[] { 210, 210, 240, 240 }, 4);
	g.drawPolyline(new int[] { 160, 160, 190, 190 }, new int[] {240, 210, 240, 210 }, 4);

	// Printing texts
	g.setColor(Color.BLACK);
	g.setFont(new Font("Monospaced", Font.PLAIN, 14));
	g.drawString("Drawn with JGraphix", 10, 275);

	df.refresh();

	System.out.println("done.");
}
 
开发者ID:imagingbook,项目名称:JGraphix,代码行数:44,代码来源:JGraphix_Example_1.java


注:本文中的java.awt.Graphics2D.drawPolygon方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。