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


Java Graphics.drawPolygon方法代码示例

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


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

示例1: drawSingleAgent

import java.awt.Graphics; //导入方法依赖的package包/类
public void drawSingleAgent(Graphics g, Position pos, Color color) {
    int[] xPoint = null;
    int[] yPoint = null;
    int x = pos.getX(), y = pos.getY();
    String heading = pos.getHeading();
    if (heading.equals(UP)) {
        xPoint = new int[] { x * cellSizeW, (x + 1) * cellSizeW, (int) ((0.5 + x) * cellSizeW) };
        yPoint = new int[] { (y + 1) * cellSizeH, (y + 1) * cellSizeH, y * cellSizeH };
    } else if (heading.equals(DOWN)) {
        xPoint = new int[] { x * cellSizeW, (x + 1) * cellSizeW, (int) ((0.5 + x) * cellSizeW) };
        yPoint = new int[] { y * cellSizeH, y * cellSizeH, (y + 1) * cellSizeH };
    } else if (heading.equals(LEFT)) {
        xPoint = new int[] { (x + 1) * cellSizeW, (x + 1) * cellSizeW, x * cellSizeW };
        yPoint = new int[] { y * cellSizeH, (y + 1) * cellSizeH, (int) ((0.5 + y) * cellSizeH) };
    } else if (heading.equals(RIGHT)) {
        xPoint = new int[] { x * cellSizeW, x * cellSizeW, (x + 1) * cellSizeW };
        yPoint = new int[] { y * cellSizeH, (y + 1) * cellSizeH, (int) ((0.5 + y) * cellSizeH) };
    }
    g.setColor(color);
    g.fillPolygon(new Polygon(xPoint, yPoint, 3));
    g.setColor(BOUND_COLOR);
    g.drawPolygon(new Polygon(xPoint, yPoint, 3));
}
 
开发者ID:JINKEHE,项目名称:Rescue-Victims,代码行数:24,代码来源:EnvView.java

示例2: paintIcon

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintIcon(java.awt.Component c, Graphics g, int x, int y) {
	// draw tool icon
	Graphics gIcon = g.create();
	ComponentDrawContext context = new ComponentDrawContext(c, null, null, g, gIcon);
	comp.getFactory().paintIcon(context, x, y, comp.getAttributeSet());
	gIcon.dispose();

	if (triangleState != TRIANGLE_NONE) {
		int[] xp;
		int[] yp;
		if (triangleState == TRIANGLE_CLOSED) {
			xp = new int[] { x + 13, x + 13, x + 17 };
			yp = new int[] { y + 11, y + 19, y + 15 };
		} else {
			xp = new int[] { x + 11, x + 19, x + 15 };
			yp = new int[] { y + 13, y + 13, y + 17 };
		}
		g.setColor(Color.LIGHT_GRAY);
		g.fillPolygon(xp, yp, 3);
		g.setColor(Color.DARK_GRAY);
		g.drawPolygon(xp, yp, 3);
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:25,代码来源:ComponentIcon.java

示例3: drawContours

import java.awt.Graphics; //导入方法依赖的package包/类
public void drawContours(Graphics g)
{
	List<Contour> contours = FindCardCandidates.getCannyContours(lastDrawn);
	for(Contour con:contours)
	{
		int[] xpoint = new int[con.external.size()];
		int[] ypoint = new int[con.external.size()];
		int i=0;
		for(Point2D_I32 pt:con.external)
		{
			xpoint[i]=pt.x;
			ypoint[i]=pt.y;
			i++;
		}
		g.drawPolygon(xpoint,ypoint,xpoint.length);
	}
}
 
开发者ID:ForOhForError,项目名称:MTG-Card-Recognizer,代码行数:18,代码来源:WebcamCanvas.java

示例4: paint

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paint(Graphics g, HandleGesture gesture) {
	List<Handle> hs = getHandles(gesture);
	int[] xs = new int[hs.size()];
	int[] ys = new int[hs.size()];
	int i = -1;
	for (Handle h : hs) {
		i++;
		xs[i] = h.getX();
		ys[i] = h.getY();
	}

	if (setForFill(g)) {
		g.fillPolygon(xs, ys, xs.length);
	}
	if (setForStroke(g)) {
		if (closed)
			g.drawPolygon(xs, ys, xs.length);
		else
			g.drawPolyline(xs, ys, xs.length);
	}
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:23,代码来源:Poly.java

示例5: drawTrapezoid

import java.awt.Graphics; //导入方法依赖的package包/类
static void drawTrapezoid(Graphics g, Bounds bds, Direction facing, int facingLean) {
	int wid = bds.getWidth();
	int ht = bds.getHeight();
	int x0 = bds.getX();
	int x1 = x0 + wid;
	int y0 = bds.getY();
	int y1 = y0 + ht;
	int[] xp = { x0, x1, x1, x0 };
	int[] yp = { y0, y0, y1, y1 };
	if (facing == Direction.WEST) {
		yp[0] += facingLean;
		yp[3] -= facingLean;
	} else if (facing == Direction.NORTH) {
		xp[0] += facingLean;
		xp[1] -= facingLean;
	} else if (facing == Direction.SOUTH) {
		xp[2] -= facingLean;
		xp[3] += facingLean;
	} else {
		yp[1] += facingLean;
		yp[2] -= facingLean;
	}
	GraphicsUtil.switchToWidth(g, 2);
	g.drawPolygon(xp, yp, 4);
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:26,代码来源:Plexers.java

示例6: print

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void print(Graphics g, GraphicPanel f)
{
	if(heuristiqueOrientation != null)
	{
		double n = 40;
		XY_RW point1 = new XY_RW(n, 0), point2 = new XY_RW(-n / 2, n / 2), point3 = new XY_RW(-n / 2, -n / 2);
		point1.rotate(heuristiqueOrientation).plus(node.position);
		point2.rotate(heuristiqueOrientation).plus(node.position);
		point3.rotate(heuristiqueOrientation).plus(node.position);
		int[] X = { f.XtoWindow((int) point1.getX()), f.XtoWindow((int) point2.getX()), f.XtoWindow((int) point3.getX()) };
		int[] Y = { f.YtoWindow((int) point1.getY()), f.YtoWindow((int) point2.getY()), f.YtoWindow((int) point3.getY()) };

		g.drawPolygon(X, Y, 3);
	}
}
 
开发者ID:PFGimenez,项目名称:The-Kraken-Pathfinding,代码行数:17,代码来源:DStarLiteNode.java

示例7: paintIcon

import java.awt.Graphics; //导入方法依赖的package包/类
public void paintIcon(Component c, Graphics g, int x, int y) {
  Dimension size = c.getSize();
  Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
  g2.setColor(Color.GRAY);
  g2.drawPolygon(xPoints, yPoints, 3);
  if (c.isEnabled()) {
    g2.setColor(Color.BLACK);
    g2.fillPolygon(xPoints, yPoints, 3);
  }
  g2.dispose();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:12,代码来源:MenuScroller.java

示例8: paintComponent

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintComponent(Graphics g)
{
   super.paintComponent(g); 

   // draw polygon with Polygon object
   int[] xValues = {20, 40, 50, 30, 20, 15};
   int[] yValues = {50, 50, 60, 80, 80, 60};
   Polygon polygon1 = new Polygon(xValues, yValues, 6);
   g.drawPolygon(polygon1);

   // draw polylines with two arrays
   int[] xValues2 = {70, 90, 100, 80, 70, 65, 60};
   int[] yValues2 = {100, 100, 110, 110, 130, 110, 90};
   g.drawPolyline(xValues2, yValues2, 7);

   // fill polygon with two arrays
   int[] xValues3 = {120, 140, 150, 190};
   int[] yValues3 = {40, 70, 80, 60};
   g.fillPolygon(xValues3, yValues3, 4);

   // draw filled polygon with Polygon object
   Polygon polygon2 = new Polygon();
   polygon2.addPoint(165, 135);
   polygon2.addPoint(175, 150);
   polygon2.addPoint(270, 200);
   polygon2.addPoint(200, 220);
   polygon2.addPoint(130, 180);
   g.fillPolygon(polygon2);
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:31,代码来源:PolygonsJPanel.java

示例9: paintIcon

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
  Dimension size = c.getSize();
  Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
  g2.setColor(Color.GRAY);
  g2.drawPolygon(xPoints, yPoints, 3);
  if (c.isEnabled()) {
    g2.setColor(Color.BLACK);
    g2.fillPolygon(xPoints, yPoints, 3);
  }
  g2.dispose();
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:13,代码来源:MenuScroller.java

示例10: runTest

import java.awt.Graphics; //导入方法依赖的package包/类
public void runTest(Object ctx, int numReps) {
    RenderTests.Context rctx = (RenderTests.Context) ctx;
    // subtract 1 to account for the fact that lines are drawn to
    // and including the final coordinate...
    int size = rctx.size - 1;
    int x = rctx.initX;
    int y = rctx.initY;
    int hexaX[] = new int[6];
    int hexaY[] = new int[6];
    Graphics g = rctx.graphics;
    g.translate(rctx.orgX, rctx.orgY);
    Color rCArray[] = rctx.colorlist;
    int ci = rctx.colorindex;
    do {
        hexaX[0] = x;
        hexaX[1] = hexaX[5] = x+size/4;
        hexaX[2] = hexaX[4] = x+size-size/4;
        hexaX[3] = x+size;
        hexaY[1] = hexaY[2] = y;
        hexaY[0] = hexaY[3] = y+size/2;
        hexaY[4] = hexaY[5] = y+size;

        if (rCArray != null) {
            g.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g.drawPolygon(hexaX, hexaY, 6);
        if ((x -= 3) < 0) x += rctx.maxX;
        if ((y -= 1) < 0) y += rctx.maxY;
    } while (--numReps > 0);
    rctx.colorindex = ci;
    g.translate(-rctx.orgX, -rctx.orgY);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:RenderTests.java

示例11: paintIcon

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
    Dimension size = c.getSize();
    Graphics g2 = g.create(size.width / 2 - 5, size.height / 2 - 5, 10, 10);
    g2.setColor(Color.GRAY);
    g2.drawPolygon(xPoints, yPoints, 3);
    if (c.isEnabled()) {
        g2.setColor(Color.BLACK);
        g2.fillPolygon(xPoints, yPoints, 3);
    }
    g2.dispose();
}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:13,代码来源:MenuScroller.java

示例12: print

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void print(Graphics g, GraphicPanel f)
{
	double n = 40;
	XY_RW point1 = new XY_RW(n, 0), point2 = new XY_RW(-n / 2, n / 2), point3 = new XY_RW(-n / 2, -n / 2);
	point1.rotate(orientationGeometrique).plus(position);
	point2.rotate(orientationGeometrique).plus(position);
	point3.rotate(orientationGeometrique).plus(position);
	int[] X = { f.XtoWindow((int) point1.getX()), f.XtoWindow((int) point2.getX()), f.XtoWindow((int) point3.getX()) };
	int[] Y = { f.YtoWindow((int) point1.getY()), f.YtoWindow((int) point2.getY()), f.YtoWindow((int) point3.getY()) };

	g.drawPolygon(X, Y, 3);
}
 
开发者ID:PFGimenez,项目名称:The-Kraken-Pathfinding,代码行数:14,代码来源:Cinematique.java

示例13: print

import java.awt.Graphics; //导入方法依赖的package包/类
@Override
public void print(Graphics g, GraphicPanel f)
{
	int[] X = new int[4];
	X[0] = (int) coinBasDroiteRotate.getX();
	X[1] = (int) coinHautDroiteRotate.getX();
	X[2] = (int) coinHautGaucheRotate.getX();
	X[3] = (int) coinBasGaucheRotate.getX();

	int[] Y = new int[4];
	Y[0] = (int) coinBasDroiteRotate.getY();
	Y[1] = (int) coinHautDroiteRotate.getY();
	Y[2] = (int) coinHautGaucheRotate.getY();
	Y[3] = (int) coinBasGaucheRotate.getY();

	for(int i = 0; i < 4; i++)
	{
		X[i] = f.XtoWindow(X[i]);
		Y[i] = f.YtoWindow(Y[i]);
	}
	g.drawPolygon(X, Y, 4);
	
	Color c = g.getColor();
	Color cTransparent = new Color(c.getRed(), c.getGreen(), c.getBlue(), 30);
	g.setColor(cTransparent);
	
	g.fillPolygon(X, Y, 4);
}
 
开发者ID:PFGimenez,项目名称:The-Kraken-Pathfinding,代码行数:29,代码来源:RectangularObstacle.java

示例14: drawArea

import java.awt.Graphics; //导入方法依赖的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(Graphics g, Vector<Point2D> allConvex, Vector<Point2D> allDominants, Color area, Color maskedoff) {
	//The first color in the maskedoff color because after will be draw
	//the non-maskedoff areas
	g.setColor(maskedoff);
	Polygon poly = new Polygon();

	DPoint p;
	p = (DPoint) allConvex.get(0);

	poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y);

	//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((int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
	}

	p = (DPoint) allConvex.get(allConvex.size() - 1);
	poly.addPoint(1 + tran_x, tran_y - (int) (p.getY() * scale));
	poly.addPoint(1 + tran_x, tran_y);
	g.fillPolygon(poly);
	g.setColor(Color.GRAY);
	g.drawPolygon(poly);

	//Draw the non-maskedoff area for each dominant point
	Polygon masked = new Polygon();
	g.setColor(area);

	int k = 0;
	for (k = 0; k < allDominants.size() - 1; k++) {
		p = (DPoint) allDominants.get(k);
		if (!p.intEquals((DPoint) allDominants.get(k + 1))) {
			masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
			g.fillPolygon(masked);
		}
	}
	//Last area is 1 point small
	p = (DPoint) allDominants.get(k);
	masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale) + 1);
	g.fillPolygon(masked);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:50,代码来源:PainterConvex2D.java

示例15: drawArea

import java.awt.Graphics; //导入方法依赖的package包/类
/**
* This function draw te 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(Graphics g, Vector<Point2D> allConvex, Vector<Point2D> allDominants, Color area, Color maskedoff) {
	//The first color in the maskedoff color beacause after will be draw
	//the non-maskedoff areas
	g.setColor(maskedoff);
	Polygon poly = new Polygon();

	DPoint p;
	p = (DPoint) allConvex.get(0);

	poly.addPoint((int) (p.getX() * scale) + tran_x, tran_y);

	//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((int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
	}

	p = (DPoint) allConvex.get(allConvex.size() - 1);
	poly.addPoint(1 + tran_x, tran_y - (int) (p.getY() * scale));
	poly.addPoint(1 + tran_x, tran_y);
	g.fillPolygon(poly);
	g.setColor(Color.GRAY);
	g.drawPolygon(poly);

	//Draw the non-maskedoff area for each dominant point
	Polygon masked = new Polygon();
	g.setColor(area);

	int k = 0;
	for (k = 0; k < allDominants.size() - 1; k++) {
		p = (DPoint) allDominants.get(k);
		if (!p.intEquals((DPoint) allDominants.get(k + 1))) {
			masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale));
			g.fillPolygon(masked);
		}
	}
	//Last area is 1 point small
	p = (DPoint) allDominants.get(k);
	masked = twoPointRectangle(1 + tran_x, tran_y, (int) (p.getX() * scale) + tran_x, tran_y - (int) (p.getY() * scale) + 1);
	g.fillPolygon(masked);
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:50,代码来源:PainterConvex2D.java


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