List of usage examples for java.awt Polygon addPoint
public void addPoint(int x, int y)
From source file:Main.java
public static void main(String[] argv) { JFrame f = new JFrame(); f.setSize(400, 300);//from ww w . j ava 2 s .c om Polygon p = new Polygon(); p.addPoint(10, 10); p.addPoint(100, 300); p.addPoint(300, 300); p.addPoint(10, 10); PolygonButton btn = new PolygonButton(p, "button"); f.getContentPane().add(btn); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; f.addWindowListener(wndCloser); f.setVisible(true); }
From source file:Main.java
/** * Draws a single arrow head//from w ww .ja v a 2s . co m * * @param aG * the canvas to draw on; * @param aXpos * the X position of the arrow head; * @param aYpos * the (center) Y position of the arrow head; * @param aFactor * +1 to have a left-facing arrow head, -1 to have a right-facing * arrow head; * @param aArrowWidth * the total width of the arrow head; * @param aArrowHeight * the total height of the arrow head. */ public static final void drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight) { final double halfHeight = aArrowHeight / 2.0; final int x1 = aXpos + (aFactor * aArrowWidth); final int y1 = (int) Math.ceil(aYpos - halfHeight); final int y2 = (int) Math.floor(aYpos + halfHeight); final Polygon arrowHead = new Polygon(); arrowHead.addPoint(aXpos, aYpos); arrowHead.addPoint(x1, y1); arrowHead.addPoint(x1, y2); aG.fill(arrowHead); }
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius) { if (sides < 3) { return new Ellipse2D.Float(0, 0, 10, 10); }// ww w . j av a 2 s.com AffineTransform trans = new AffineTransform(); Polygon poly = new Polygon(); for (int i = 0; i < sides; i++) { trans.rotate(Math.PI * 2 / (float) sides / 2); Point2D out = trans.transform(new Point2D.Float(0, outsideRadius), null); poly.addPoint((int) out.getX(), (int) out.getY()); trans.rotate(Math.PI * 2 / (float) sides / 2); if (insideRadius > 0) { Point2D in = trans.transform(new Point2D.Float(0, insideRadius), null); poly.addPoint((int) in.getX(), (int) in.getY()); } } return poly; }
From source file:fungus.VisualizerTransformers.java
public static Shape createRegularPolygon(int sides, int radius) { Polygon p = new Polygon(); double a = 2 * Math.PI / sides; for (int i = 0; i < sides; i++) p.addPoint((int) (radius * Math.sin(a * i)), (int) (radius * -Math.cos(a * i))); return p;/* w w w. j av a 2 s .com*/ }
From source file:ec.util.chart.swing.JTimeSeriesRendererSupport.java
private static Shape createShape(double x, double y, Rectangle2D hotspot) { Area result = new Area(new RoundRectangle2D.Double(hotspot.getX(), hotspot.getY(), hotspot.getWidth(), hotspot.getHeight(), 8, 8)); boolean right = hotspot.getMinX() > x; Polygon po = new Polygon(); po.addPoint(0, 0); po.addPoint(0, 10);/*from www.java2 s.co m*/ po.addPoint(10, 0); AffineTransform af = new AffineTransform(); if (right) { af.translate(hotspot.getX() - 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(-Math.PI / 4); } else { af.translate(hotspot.getMaxX() + 7, hotspot.getY() + hotspot.getHeight() / 2); af.rotate(Math.PI * 3 / 4); } Shape shape = af.createTransformedShape(po); result.add(new Area(shape)); return result; }
From source file:edu.ku.brc.ui.GraphicsUtils.java
/** * Draws an arrow from <code>(xCenter,yCenter)</code> to <code>(x,y)</code>. * Code stolen from http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135. * /*from w ww .j a va2s .c om*/ * @param g the graphics context to draw in * @param headSize the size of the arrow head * @param xCenter the x-coord of the arrow tail * @param yCenter the y-coord of the arrow tail * @param x the x-coord of the arrow head's tip * @param y the y-coord of the arrow head's tip * @param stroke the <code>Stroke</code> to use */ public static void drawArrow(Graphics g, int xCenter, int yCenter, int x, int y, int headSize, float stroke) { Graphics2D g2d = (Graphics2D) g; g2d.addRenderingHints(hints); double aDir = Math.atan2(xCenter - x, yCenter - y); Stroke origStroke = g2d.getStroke(); g2d.setStroke(new BasicStroke(stroke)); // make the arrow head solid even if dash pattern has been specified g2d.drawLine(x, y, xCenter, yCenter); Polygon tmpPoly = new Polygon(); int i1 = 2 * headSize + (int) stroke; //(stroke * 2); int i2 = headSize + (int) stroke; // make the arrow head the same size regardless of the length length tmpPoly.addPoint(x, y); // arrow tip tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5)); tmpPoly.addPoint(x, y); // arrow tip g2d.drawPolygon(tmpPoly); g2d.fillPolygon(tmpPoly); // remove this line to leave arrow head unpainted g2d.setStroke(origStroke); }
From source file:RedBlueBox.java
public void paintComponent(Graphics g) { Insets insets = getInsets();/* w w w .jav a 2s . com*/ int endX = getWidth() - insets.right; int endY = getHeight() - insets.bottom; // get the top-left corner int x = insets.left; int y = insets.top; g.setColor(Color.RED); Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(endX, y); p.addPoint(x, endY); g.fillPolygon(p); g.setColor(Color.BLUE); p.reset(); p.addPoint(endX, y); p.addPoint(x, endY); p.addPoint(endX, endY); g.fillPolygon(p); }
From source file:DrawPolyPanel.java
public void paintComponent(Graphics g) { super.paintComponent(g); Polygon p = new Polygon(); for (int i = 0; i < 5; i++) p.addPoint((int) (100 + 50 * Math.cos(i * 2 * Math.PI / 5)), (int) (100 + 50 * Math.sin(i * 2 * Math.PI / 5))); g.drawPolygon(p);//ww w .j a v a2s . c o m Polygon s = new Polygon(); for (int i = 0; i < 360; i++) { double t = i / 360.0; s.addPoint((int) (150 + 50 * t * Math.cos(8 * t * Math.PI)), (int) (150 + 50 * t * Math.sin(8 * t * Math.PI))); } g.drawPolygon(s); }
From source file:Main.java
public void paint(Graphics g) { super.paintComponent(g); int radius = 40; int centerX = 50; int centerY = 100; Polygon p = new Polygon(); centerX = 150;//from www. j av a 2s . com for (int i = 0; i < 5; i++) p.addPoint((int) (centerX + radius * Math.cos(i * 2 * Math.PI / 5)), (int) (centerY + radius * Math.sin(i * 2 * Math.PI / 5))); g.fillPolygon(p); }
From source file:Test.java
License:asdf
private Polygon getPolygon() { int x1Points[] = { 0, 20, 100, 200, 330, 300, 200, 100 }; int y1Points[] = { 100, 200, 310, 300, 200, 100, 10, 0 }; Polygon polygon = new Polygon(); for (int i = 0; i < y1Points.length; i++) { polygon.addPoint(x1Points[i], y1Points[i]); }//from w w w.j a v a 2 s.com return polygon; }